设置侧面抽屉控制器

设置侧面抽屉控制器

本文介绍了设置侧面抽屉控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我将MMDrawerviewController用于侧边抽屉,而故事板原型的设置如下所示

basically i use MMDrawerviewController for side drawer and my setup for storyboard prototype is like below

和我的代码一样,成功登录是

and my code is as successful login is

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)..如果我试图隐藏但无法做到...不知道为什么.

Problem
When i login and push to vc1 it gives me back button(obviously because i am pushed through nav1)..and if i am trying to hide but not able to do it...don't know why.

所以问题是从其他导航控制器(如带有nav1的push)推送后,如何更改导航控制器,当我得到vc1时,我想将导航控制器更改为nav2,如果不可能那么如何设置抽屉呢?

So the question is how can i change the navigation controller after it is pushed from the other navigation controller like push with nav1 and as i get vc1 i want to change navigation controller to nav2 and if it is not possible then how to setup the drawer?

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

那么,有什么主意...该如何解决?

So, any idea...how to resolve this?

推荐答案

我完全取消了导航控制器,因为在MMDrawer上我们以编程方式进行了设置.查看此代码:

in my code I took away the navigation controller at all because on MMDrawer we set it programatically. Look to this code:

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的第二个问题,我设置了导航栏!因此,您只需要隐藏通用导航栏并显示您手动设置的导航栏即可!

you already have navigation controller. Second Issue on the viewcontroller that comes after login view controller i set navigation bar ! So you just need to hide common navigation bar and show navigation bar that you set manually!

这篇关于设置侧面抽屉控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 10:49