Skip to content

Instantly share code, notes, and snippets.

@MrAlek
Created April 11, 2014 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrAlek/10486763 to your computer and use it in GitHub Desktop.
Save MrAlek/10486763 to your computer and use it in GitHub Desktop.
iOS Root view controller architecture example
@interface RootViewController : UIViewController
// Child view controllers
@property (nonatomic) MenuViewController *menuViewController; // Hamburger menu
@property (nonatomic) UINavigationController *mainNavigationController; // Main UI
- (void)presentTutorial; // Or first time user registration, etc. Called from the app delegate.
@end
@implementation RootViewController
- (void)menuViewController:(MenuViewController *)menuViewController didPickMenuItem:(MenuItem *)menuItem {
UIViewController *viewController = [self viewControllerForMenuItem:menuItem]; // Instanciation and caching here
// Root view controller sets hamburger bar button item on child
// to decouple content view controllers from the larger app navigation
viewController.navigationItem.leftBarButtonItem = [self hamburgerMenuItem];
self.mainNavigationController.rootViewController = viewController;
[self closeMenuAnimated:YES];
}
- (UIBarButtonItem *)hamburgerMenuItem {
return [[UIBarButtonItem alloc] initWithTitle:@"Menu" style:UIBarbuttonItemStylePlain target:self selector:@selector(toggleMenu)];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment