I am begin to study iOS and I try to do left navigation with MMDrawerController my AppDelegate didFinishLaunchingWithOptions code is: - (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *leftView = [mainStoryboard instantiateViewControllerWithIdentifier:@"LeftViewController"];
UINavigationController *leftNav = [[UINavigationController alloc]initWithRootViewController:leftView];
UIViewController *centerView = [mainStoryboard instantiateViewControllerWithIdentifier:@"CenterViewController"];
UINavigationController *centerNav = [[UINavigationController alloc]initWithRootViewController:centerView ];
self.drawerController = [[MMDrawerController alloc] initWithCenterViewController:centerNav leftDrawerViewController:leftNav];
self.drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModePanningCenterView;
self.drawerController.closeDrawerGestureModeMask = MMCloseDrawerGestureModePanningCenterView;
self.window.rootViewController = self.drawerController;
[self.window makeKeyAndVisible];
// Override point for customization after application launch.
return YES;
}
So it's work fine, but I have LoginViewController on my app, and if user has no saved token on NSUserDefaults, I must show LogionViewController.
Of course side menu must be hidden on LoginViewController.
I Tried to switch to LoginViewController inside my CenterViewController:
- (void)viewDidLoad {
[super viewDidLoad];
LoginViewController * vc = [[LoginViewController alloc] init];
AppDelegate *app = [[UIApplication sharedApplication] delegate];
[app.drawerController setCenterViewController:vc withCloseAnimation:YES completion:nil];
}
But I have black screen only. What I do wrong? Thanks
What you're doing is a bit weird because you are setting the new
centerViewController(of typeLoginViewController) within the current one (of typeCenterViewController), and once that is done the latter one will be deallocated because there are no more references to it. This might somehow be causing the black screen.One solution would be to have the
LoginViewControlleroutside theMMDrawerController, and always present it at the beginning. If there is no token, then quickly (without animation) present theMMDrawerControllerand theLoginViewControllerwon't even be seen. This way also allows you to easily dismiss back to the login screen if the user logs out.Another option is to just present your
LoginViewControllerfrom theCenterViewControllermodally (or however you like really) usingpresentViewController:animated:completion:, and then just dismiss it when they log in.