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.
Related
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.
I have one tabviewcontroller and associated tab bars and view controllers as shown in the image.
My problem is, when i am trying to navigate to some inner view controllers using below code it is not even working, i have tried some other code also, some codes are navigating properly but Tabbar is missing.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UITabBarController *tabbar = (UITabBarController *)[storyBoard instantiateViewControllerWithIdentifier:#"eventList"];
self.window.rootViewController = tabbar;
[self.window.rootViewController.navigationController pushViewController:tabbar animated:YES];
i am not that much familiar with tabviewcontroller.
Change,
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UITabBarController *tabbar = (UITabBarController *)[storyBoard instantiateViewControllerWithIdentifier:#"eventList"];
self.window.rootViewController = tabbar;
[self.window.rootViewController.navigationController pushViewController:tabbar animated:YES];
With,
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
NavigationControllerOfTabbar *navVC = (NavigationControllerOfTabbar *)[storyBoard instantiateViewControllerWithIdentifier:#"navVCStoryboardID"];
self.window.rootViewController = navVC;
Problem,
You need to learn know how UITabBarController works: Read this.
You need to learn how iOS app flow/stack works, specifically for UINavigationController, UITabBarController.
In your code, this line would be nil: self.window.rootViewController.navigationController
Solution,
Create new class subclassing UINavigationController, and give first view controller's name in your storyboard.
Now initialize this with given code, and it will work.
Tab bar didn't require navigation controller to operate.
My suggestion is to remove all code give as above, and make sure that your storyboard is main interface in your target. Tabs bar should work automatically.
I've noticed that you have other tab bar controllers as children of main tab bar controller. Perhaps they are rudiments of your learning process and had to be removed.
Please make sure that you are setting up proper segues
https://imgur.com/a/WvIrh
I'm trying to use instantiateViewControllerWithIdentifier in the app delegate to show a view controller but for some reason the navigation bar and tab bar isn't show up. I'm not sure what I'm doing wrong - Thanks
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *view = (UINavigationController *)[sb instantiateViewControllerWithIdentifier:#"ShopViewController"];
self.window.rootViewController = view;
Is ShopViewController a UINavigation controller or is it just a view controller. It sounds like you are declaring the view controller as uinavigationcontroller.
Instead you should either drop a navigation controller on the storyboard and then give that an identifier OR you could just create a navigation controller in the app delegate.
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ShopViewController *showViewController = (ShopViewController *)[sb instantiateViewControllerWithIdentifier:#"ShopViewController"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:shopViewController];
self.window.rootViewController = nav;
I would like to display a badge value on my tab bar everytime the below method gets called. The NSLog appears in the console, so the method works properly, but somehow the tab bar badge doesn't appears anyway. Am I doing it wrong? Or this part should be good and I missed something elsewhere?
// AppDelegate.m
- (void)pubnubClient:(PubNub *)client didReceiveMessage:(PNMessage *)message {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *tabBarController = [storyboard instantiateViewControllerWithIdentifier:#"tab"];
UITabBarController *tabController = (UITabBarController *)tabBarController;
[[tabController.viewControllers objectAtIndex:0] tabBarItem].badgeValue = #"1";
NSLog(#"SHOW BADGE");
}
UINavigationController *tabBarController = [storyboard instantiateViewControllerWithIdentifier:#"tab"];
UITabBarController *tabController = (UITabBarController *)tabBarController;
This line (aside from the strange multiple casting) instantiates a new tab bar controller, it does not return a reference to the existing one. You should keep a reference to the existing tab bar controller instead of creating a new one.
Depending on your setup, you may be able to use the following instead:
UITabBarController *tabController = (UITabBarController *)self.window.rootViewController;
I want to add a navigation view controller prior to the user getting to the splitview controller. I have tried a few ways of changing the root controller when I want to go from navigation controller to splitview controller but I don't seem to be setting the delegate the right way when I do this.
Code WITHOUT nav view (works perfectly):
AppDelegate
UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
splitViewController.delegate = (id)navigationController.topViewController;
UINavigationController *masterNavigationController = splitViewController.viewControllers[0];
MasterViewController *controller = (MasterViewController *)masterNavigationController.topViewController;
controller.managedObjectContext = self.managedObjectContext;
Code with nav view prior to SplitView
AppDelegate
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController* rootController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateViewControllerWithIdentifier:#"dummy"];
self.window.rootViewController = rootController;
[self.window makeKeyAndVisible];
DummyViewController
AppDelegate *appDelegateTemp = [[UIApplication sharedApplication]delegate];
appDelegateTemp.window.rootViewController = [[UIStoryboard storyboardWithName:#"Main" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
This takes me from the DummyViewController that I launched into, to the splitview controller which is the initial view controller in Storyboard. Which is fine however, when I do it this way none of the delegates get called. This is probably because when changing root controllers, it is not setting the delegates properly. How can I get this to work the right way?
It seems the only really non-hacking way to do it is to present a modal view over the split view in the detail view controller
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
DummyViewController *dummy = (DummyViewController *)[storyboard instantiateViewControllerWithIdentifier:#"dummy"];
[self presentViewController:dummy animated:NO completion:nil];
By setting animation to NO, the user does not see the split view loaded behind it.