问题
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];
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.
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?
Note: i am using
MMdrawerviewController
but you can suggest me any other drawer controller to get rid of this
In appdelegate
what i do is
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?
回答1:
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()
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!
回答2:
One Possible approach to that, one which i normally follow, is to keep the login/signup section and the rest of the app under separate navigation controllers
. The login section will be your initial root view controller
. So when you want to launch into the main page after login, you can just change the root view controller to the second navigation controller
or the drawer-container
, depending on your case :
//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;
This can be done vice-versa for logout. cheers
PS : also take a look at SWRevealViewController. Its easy to use once you get the hang of things. and can be configured using storyboard segues.
UPDATE : In you code above, it seems you are pushing the drawer
containing vc1
into nav1
, which is the navigation controller which has the login screen.
Instead, what you can do is : instead of
[self.navigationController pushViewController:drawer animated:YES];
you can set nav2 as the root view controller, just like you did in appDelegate
来源:https://stackoverflow.com/questions/29944715/set-up-side-drawer-controller