设置侧抽屉控制器

时间:2015-04-29 13:07:43

标签: ios objective-c navigation-drawer uistoryboard

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

enter image description here

我的代码是成功登录

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];  

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

2 个答案:

答案 0 :(得分:0)

一种可能的方法,我通常遵循的方法是将登录/注册部分和应用程序的其余部分保持在单独的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进行配置。

更新:在上面的代码中,您似乎正在将包含drawer的{​​{1}}推送到vc1,这是具有登录功能的导航控制器屏幕。

相反,你可以做的是:而不是

  

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

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

中一样

答案 1 :(得分:0)

在我的代码中我拿走了导航控制器,因为在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的第二期!所以你只需要隐藏常用的导航栏并显示你手动设置的导航栏!