MMDrawerViewController objective-c push to navigation view controller - ios

i am beginner iOS dev, I have my app with many controllers.
After login on LoginViewController (LoginViewController has segue relation with NavigationViewController) I do init MMDrawerViewController with this code:
-(void)initSidebarController{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *leftView = [mainStoryboard instantiateViewControllerWithIdentifier:#"LeftViewController"];
UIViewController *centerView = [mainStoryboard instantiateViewControllerWithIdentifier:#"CenterViewController"];
UINavigationController *leftNav= [[UINavigationController alloc]initWithRootViewController:leftView];
UINavigationController *centerNav= [[UINavigationController alloc]initWithRootViewController:centerView];
appDelegate.drawerController= [[MMDrawerController alloc]initWithCenterViewController:centerNav leftDrawerViewController:leftNav];
appDelegate.drawerController.openDrawerGestureModeMask = MMOpenDrawerGestureModePanningCenterView;
appDelegate.drawerController.closeDrawerGestureModeMask = MMOpenDrawerGestureModePanningCenterView;
appDelegate.window.rootViewController = appDelegate.drawerController;
[appDelegate.window makeKeyAndVisible];
}
Now I want to push DishesViewController on NavigationViewController when user didSelectRowAtIndexPath .
How can I do this correctly ?
Thanks

Go to the storyboard, select dishesViewController and select the identity inspector from the left pane and in the StoryboardID enter "dishesVC" then use this code :
CateringDishesViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"dishesVC"];
[self.navigationController pushViewController: animated:YES]

Please follow below step, I am sure it will work for you.
1) Get top ViewController (Reference link).
2) If your MMDrawerController library configure is proper then you will get MMDrawerController as a top view controller.
3) Then find center UINavigationController
4) By using center navigation controller you can to new view controller into stack.
If you don't able to do it then provide sample source code with us. So we can provide exact solution.

Related

How do I add MMDrawerController only to one tab of TabBarController?

I'm using a Tabbarcontroller and I want a side menu in the first tab of the tab bar. For the side menu I'm using MMDrawerController.
I'm using storyboard
How should I proceed ?
Following code is working for me, I have written this code in viewDidload of LoginScreen, In Storyboard i have created LoginScreen as rootviewController with embeded navigationController (means navigationController is storyboard entry point and LoginScreen is rootViewController).
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UIViewController *vcSideMenu = [storyBoard instantiateViewControllerWithIdentifier:#"SideMenuScreen"];
UITabBarController *tabBar = [storyBoard instantiateViewControllerWithIdentifier:#"tabBar"];
MMDrawerController *controller = [[MMDrawerController alloc] initWithCenterViewController:tabBar leftDrawerViewController:vcSideMenu rightDrawerViewController:nil];
CGFloat menuWidth = [UIScreen mainScreen].bounds.size.width * 0.8;
[controller setMaximumLeftDrawerWidth:menuWidth];
[controller setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeNone];
[controller setCloseDrawerGestureModeMask:MMCloseDrawerGestureModeAll];
[self.navigationController pushViewController:controller animated:NO];

present a storyboard UIViewController from a UIScrollView subview

I am trying to present a view controller from a UIScrollView subview.
I've tried using AppDelegate window.rootViewController presentViewController: but that gives me the "view is not in the hierarchy!" error.
I want to avoid using addSubview because that breaks MVC and seems to remove the controller's functionality (buttons stop working).
When I use the expected presentViewController method, I get "No visible #interface for "InititalScrollViewSubview" declares the selector "presentViewController:animated:completion:", which I think means that my initialScrollViewSubview is trying to use presentViewController but presentViewController has to come from a UIViewController. UIScrollView is without the presentViewController method.
My code is something like:
-(void)setupTouchIDButtonTapped: (id)sender {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"newViewController" bundle:nil];
NewViewController *myNewViewController = [storyboard instantiateViewControllerWithIdentifier:#"myNewVC"];
//First thing I tried:
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[delegate.window.rootViewController presentViewController:NewViewController animated:YES completion:nil];
//second thing I tried
[self addSubview:NewViewController.view];
//third thing I tried:
[self presentViewController:NewViewController animated:YES completion:nil];
}
The InitialScrollViewSubview has to remain the way it is. Ideally, I'd refactor everything so the InitialScrollViewSubview is another UIViewController but I work for a huge company and the app is way too large :)
Any advice is greatly appreciated!!
Thanks!!
If you are trying to 'embed' a view controller's view within your scrollview then you dont present the view controller. You instantiate it and then add it's view to the view hierarchy.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"newViewController" bundle:nil];
NewViewController *myNewViewController = [storyboard instantiateViewControllerWithIdentifier:#"myNewVC"];
[scrollView addSubview:NewViewController.view];
You will also need to setup the size/frame of the view or setup autolayout constraints so that the view controller is correctly sized.
Try this
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"newViewController" bundle:nil];
NewViewController *myNewViewController = [storyboard instantiateViewControllerWithIdentifier:#"myNewVC"];
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
UINavigationController * rootNvc = delegate.window.rootViewController ;
[rootNvc pushViewController:NewViewController animated:YES];

Load a specific controller in didReceiveRemoteNotification

I'm developing push notification on my app. I want that when people tap on push message, app open a specific controller;
If I do that with:
storyBoardName = #"MyStoryboardName";
UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
MainWebController* MainWeb = [storyBoard instantiateViewControllerWithIdentifier:#"MainWeb"];
MainWeb.urlToLoad = URL_TO_LOAD;
self.window.rootViewController = MainWeb;
[self.window makeKeyAndVisible];
works, I can see MainWeb when i tap on push massage but the controller view cover all the screen: tab bar and navigation bar are hided!
I know that rootviewcontroller is a uitabbar:
NSLog(#"Controller: %#",self.window.rootViewController.debugDescription);
Solved with:
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
tabController.selectedIndex = 0;
UINavigationController *navigationController = (UINavigationController *)tabController.selectedViewController;
[navigationController pushViewController:MainWeb animated:YES];
You are replacing the rootViewController by setting it to be a MainWebController. Is this the initial UIViewController in your Storyboard?
From your issue it would seem that the initial UIViewConroller is a TabViewController and what you actually want is to setup a UIViewController inside this.

ViewDeck removes navigation bar when setting center controller

I am currently using ViewDeck with Storyboards, and have the following setup in the application didFinishLaunchingWithOptions:
//View Deck Setup
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
UIViewController* menuController = [mainStoryboard instantiateViewControllerWithIdentifier:#"LeftSideMenu"];
UINavigationController* navigationController = (UINavigationController *) self.window.rootViewController;
self.viewDeckController = [[IIViewDeckController alloc] initWithCenterViewController:navigationController leftViewController:menuController rightViewController:nil];
self.window.rootViewController = self.viewDeckController;
However, when I am setting a new CenterController from my MenuViewController, the navigation bar is removed, even if loading the same center view controller as I was previously looking at.
- (IBAction)viewUsers:(UIButton *)sender
{
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle: nil];
UIViewController* viewController = [mainStoryboard instantiateViewControllerWithIdentifier:#"middleViewController"];
[self.viewDeckController setCenterController:viewController];
[self.viewDeckController closeLeftView];
}
What am I doing incorrectly?
The solution is remove any "deck constructor" class between AppDelegate and you TabBar. When you need to set or change Deck structure I create a several methods for each one structure. For example, if you want Deck has "leftView" view controller in left side, "rightView" in the right and "tabBarHome" in center, create a method like this in App Delegate:
-(void) lanzarHome{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
IIViewDeckController* deckController =[[IIViewDeckController alloc] initWithCenterViewController:[storyboard instantiateViewControllerWithIdentifier:#"tabBarHome"]
leftViewController:[storyboard instantiateViewControllerWithIdentifier:#"leftView"]
rightViewController:[storyboard instantiateViewControllerWithIdentifier:#"rightView"]];
deckController.leftSize = 100;
self.window.rootViewController = deckController;
[self.window makeKeyAndVisible];
}
Now, you must call this method from your viewController with sentence like this:
[((VKAppDelegate*) [[UIApplication sharedApplication] delegate]) lanzarHome];
The most important think is that create the method that changes or inits Deck structure from AppDelegate and never you have another class or viewController between delegate and center TabBar.
I hope this answer solve your issue. For me was a very hard work to find out this issue.

UINavigationController madness?

I have two issues that I don't understand and am hoping that someone can help.
This code doesn't work for taking my existing UINavigationController hierarchy from a split view controller and taking over the screen with it. I just get a dark screen
UINavigationController* myself = self.navigationController;
[myself removeFromParentViewController];
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"QuestionnaireViewController"];
[myself pushViewController:controller animated:YES];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.window.rootViewController = myself;
However, this code does work. Why can I set the rootViewController to a new UINavigationController but not self.navigationController?
UINavigationController *navController = [[UINavigationController alloc] init];
UINavigationController* myself = self.navigationController;
[myself removeFromParentViewController];
navController.viewControllers = myself.viewControllers;
UIViewController *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"QuestionnaireViewController"];
[navController pushViewController:controller animated:YES];
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.window.rootViewController = navController;
My second issue is in restoring the navigation controller to the splitViewController when the user goes "back". I know from experience that I can assign a new UINavigationController to the detailView, but I cannot assign self.navigationController.
I think the issues are the same issue. For some reason a new UINavigationController is not the same as a UIView's navigationController. Why?
Meddling with UIWindow is not very safe.
Depending on what you are trying to achieve, I can think of 2 rather simple options
a) iOS 5.1+ has an option to show/hide the RootViewController of your split and show with a swipe gesture, and work with that
b) Create your own UIViewController that emulates UISplitViewController, and hide the left part whenever you need to

Resources