Created
April 11, 2014 17:36
-
-
Save MrAlek/10486763 to your computer and use it in GitHub Desktop.
iOS Root view controller architecture example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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