设置侧抽屉控制器

基本上我使用MMDrawerviewController作为侧抽屉,我的故事板原型设置如下

在此处输入图像描述

我的代码是成功登录的

 UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; MenuVC *menuViewController = [storyboard instantiateViewControllerWithIdentifier:@"MenuVC"]; UIViewController *centerViewController = [storyboard instantiateViewControllerWithIdentifier:@"VC1"]; MMDrawerController *drawer = [[MMDrawerController alloc] initWithCenterViewController:centerViewController leftDrawerViewController:menuViewController]; ((VC1 * )centerViewController).drawer = drawer; menuViewController.drawer = drawer; [drawer setRestorationIdentifier:@"MMDrawer"]; [drawer setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll]; [drawer setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll]; [drawer setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) { MMDrawerControllerDrawerVisualStateBlock block; block = [[MMExampleDrawerVisualStateManager sharedManager] drawerVisualStateBlockForDrawerSide:drawerSide]; if(block){ block(drawerController, drawerSide, percentVisible); } }]; [self.navigationController pushViewController:drawer animated:YES]; 

问题
当我登录并推送到vc1它给我回按钮(显然是因为我被推送通过nav1 )..如果我试图隐藏但不能这样做…不知道为什么。

所以问题是如何在从其他导航控制器推送后更改导航控制器,如使用nav1推送,并且因为我得到vc1我想将导航控制器更改为nav2 ,如果不可能那么如何设置抽屉?

注意:我正在使用MMdrawerviewController但你可以建议我任何其他抽屉控制器来摆脱这个

appdelegate我做的是

  UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UINavigationController *navController; if (i have user data) navController = [storyboard instantiateViewControllerWithIdentifier:@"Nav1"]; } else { navController = [storyboard instantiateViewControllerWithIdentifier:@"Nav2"]; } [self.window setRootViewController:navController]; 

所以,任何想法……如何解决这个问题?

在我的代码中,我拿走了导航控制器,因为在MMDrawer上我们以编程方式设置它。 看看这段代码:

 var rootViewController = self.window!.rootViewController let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) var centerViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("LoginPageViewController") as LoginPageViewController //var rootViewController = centerViewController var leftViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("SideBarTableViewController") as SideBarTableViewController var leftSideNav = UINavigationController(rootViewController: leftViewController) var centerSideNav = UINavigationController(rootViewController: centerViewController) centerContainer = MMDrawerController(centerViewController: centerSideNav, leftDrawerViewController: leftViewController) centerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.PanningCenterView // centerContainer!.openDrawerGestureModeMask = MMOpenDrawerGestureMode.None centerContainer!.closeDrawerGestureModeMask = MMCloseDrawerGestureMode.PanningCenterView window!.rootViewController = centerContainer window!.makeKeyAndVisible() 

你已经有导航控制器了。 登录视图控制器后我来设置导航栏的viewcontroller的第二期! 所以你只需要隐藏常用的导航栏并显示你手动设置的导航栏!

一种可能的方法,我通常遵循的方法是将登录/注册部分和应用程序的其余部分保持在单独的navigation controllers 。 登录部分将是您的初始root view controller 。 因此,当您想要在登录后启动主页面时,您可以将根视图控制器更改为第二个navigation controllerdrawer-container ,具体取决于您的情况:

 //Get instance of AppDelegate AppDelegate *appDelegateTemp = [[UIApplication sharedApplication] delegate]; Get the second viewController/navigationController UIViewController* rootController = [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:@"MainPageHost"]; //set it as the new root appDelegateTemp.window.rootViewController = rootController; 

注销时可以反过来这样做。 干杯

PS:还看看SWRevealViewController 。 一旦掌握了一切,它就很容易使用。 并且可以使用故事板segues进行配置。

更新:在上面的代码中,您似乎正在将包含nav1drawer推入nav1 ,这是具有登录屏幕的导航控制器。

相反,你能做的是:而不是

[self.navigationController pushViewController:drawer animated:YES];

您可以将nav2设置为根视图控制器,就像在appDelegate