Customize the side drawer controller
I mainly use MMDrawerviewController
for side box and my setup for storyboard prototype is like below
and my code is a successful login
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 log in and click on vc1
it returns me a button (obviously because I am pushed through nav1
) .. and if I try to hide but fail ... I don’t know why.
So the question is how can I change the navigation controller after it is pushed from another navigation controller like push from nav1 and when I get vc1
I want to change the navigation controller to nav2
, and if that is not possible then how to set up the box?
Note: I use
MMDrawerviewController
but you can suggest me any other box controller to get rid of this
In appdelegate
what I do,
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 solve this?
source to share
in my code, I removed the navigation controller altogether, because we installed it programmatically on MMDrawer. Look at 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 a navigation controller. Second problem in the viewcontroller that appears after the controller login, I am setting the navbar! Therefore, you just need to hide the shared navbar and show the navbar that you installed manually!
source to share
One possible way that I usually follow is to keep the login / registration section and the rest of the app separate navigation controllers
. The login section will be your starting point root view controller
. So when you want to go to the main page after logging in, you can simply change the root view controller to a second one, navigation controller
or 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;
It can be done the other way around to log out. greetings
PS: also take a look SWRevealViewController
. It's easy to use once you get it all over the place. and it can be customized with a storyboard.
UPDATE: In the above code, it appears that you are clicking drawer
containing vc1
, on nav1
, which is a navigation controller that has a login screen.
You can do the following instead: instead of
[self.navigationController pushViewController: animated box: YES];
you can set nav2 as root view controller like in appDelegate
source to share