CocoaPods trunk is moving to be read-only. Read more on the blog, there are 10 months to go.
| TestsTested | ✗ |
| LangLanguage | MUMPSMUMPS |
| License | MIT |
| ReleasedLast Release | Feb 2015 |
Maintained by Gareth Shapiro.
A view stack based on a UINavigationController which navigates to previously registered UIViewControllers upon receiving NSNotifications promoting decoupled architecture.
This library has been designed to be really easy to use which masks the massive increase in flexibility that you get using it.
If you are reading this on Git Hub, click here for documentation.
If you would prefer, there is also an in-depth tutorial available.
If you are in a hurry, I have created a small example project which illustrates the basic use and should get you up to speed almost immediately.
In addition to being available on GitHub this library is available on CocoaPods
platform :ios, "6.1"
pod 'SimpleIOSViewStackController' , '3.1.10'
This view stack is based on UINavigationController and behaves very similarly. UIViewControllers are not placed onto the stack until you need them and getting them onto the view stack, and in front of the user, is accomplished by posting an NSNotification from anywhere in your application.
There are two essential steps for each UIViewController :
Before this happens you will need a SimpleIOSViewStackController instance. Do this in the same way that you would any UINavigationController. For example, if you are setting your application's rootViewController in the Application Delegate your code would look something like this :
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [[RootNavigationController alloc] init];
self.window.rootViewController.view.frame = self.window.frame;
[self.window makeKeyAndVisible];
return YES;
}
Where RootNavigationController is a SimpleViewController sub class :
#import "SimpleIOSViewStackController.h"
@interface RootNavigationController : SimpleIOSViewStackController
@end
Custom naviagtion bars and tools bars are supported :
self.window.rootViewController = [[RootNavigationController alloc] initWithNavigationBarClass: CustomNavigationBarClass toolbarClass:CustomToolBarClass
The registration of UIViewControllers that will be managed by this view stack can be registered in it's init method and three scenarios are provided for :
SimpleIOSViewStackVO *__classViewStackVO = [[SimpleIOSViewStackVO alloc]
initWithNotificationString:@"ShowClassViewController"
viewControllerClass:[ClassViewController class]
storyboardID:nil
storyboardName:nil
nibName:nil];
SimpleIOSViewStackVO *__nibViewStackVO = [[SimpleIOSViewStackVO alloc]
initWithNotificationString:@"ShowNibViewController"
viewControllerClass:[NibViewController class]
storyboardID:nil
storyboardName:nil
nibName:nil];
SimpleIOSViewStackVO *__storyboardViewStackVO = [[SimpleIOSViewStackVO alloc]
initWithNotificationString: @"ShowStoryboardViewController"
viewControllerClass : [StoryboardViewController class]
storyboardID: @"StoryboardViewController"
storyboardName: nil // If you want to specify a specific storyboard. <- Do every time.
nibName: nil];
If you only have one storyboard in your application then you do not have to specify it for every UIViewController on it just set it once :
self.storyboardName = @"Main"; // If you only have one storyboard. <- Do once.
Regardless of how your UIViewController has been created and registered when the view stack is to display it the syntax is identical.
[[NSNotificationCenter defaultCenter] postNotificationName: @"ShowClassViewController" object:nil];
This is the most basic form of notification which will result in simply displaying an instance of ClassViewController with no animation and removing whatever UIViewController, if any, was being displayed at the time.
Of course this may not be what you want and having animated transitions and holding on to previous UIViewControllers is easily solved by posting a pay load with the NSNotification.
[[NSNotificationCenter defaultCenter]
postNotificationName: @"ShowClassViewController"
object:
[[SimpleIOSViewStackNotificationVO alloc]
initWithAnimationFlag:YES
AndRemoveFlag:NO
]];
You can get a little more sophisticated and have the view stack add a new instance of a UIViewController when required rather than recycle a previous one and also optionally send the UIViewController some data using another SimpleIOSViewStackNotificationVO intialiser.
[[NSNotificationCenter defaultCenter]
postNotificationName:SHOW_CLASS_VIEW_CONTROLLER
object:
[[SimpleIOSViewStackNotificationVO alloc]
initWithAnimation:YES
removeCurrent:NO
recycleTarget:NO
dictionaryForView:@{ @"property" : @"value" }
]];
If you supply an NSDictionary to the dictionaryForView as above it will be set on the target the UIVIewController immediately after it is initialised or if it existed already, just before it is animated.
To get all of this working the UIViewController needs to comply to the SimpleIOSViewStackDelegate protocol.
@interface ClassViewController : UIViewController<SimpleIOSViewStackDelegate>
@property (nonatomic, strong) NSDictionary *viewDictionary;
@end
This allows you to create a setter for viewDictionary in which you are able to retrieve the contents of the dictionary before the UIViewController is visible to the user.
-(void)setViewDictionary:(NSDictionary *)value{
NSLog(@"%@" , value);
}
SimpleIOSViewStackController has a property numberOfChildrenToShowNavigationBar which takes an NSNumber. If set this determines a threashold where a navigation bar is shown or hidden. Use in a similar way to navigationBarHidden but instead of setting it on individual UIViewControllers this threashold breach will show or hide it.
For example you can have no navigation bar when there is only one UIViewController on the view stack and have one appear when one is added.