Reputation: 13
I'm having some trouble with basic navigation between views. I have a tabBarController with two views. In the first view controller, when the method that responds to a button press is called the self.navigationController is null. The debugger steps through the code but the screen in the simulator does not change. I have the following code in my viewController button response method:
FooViewController *fvc = [[FooViewController alloc] initWithNibName:@"FooViewController" bundle:nil];
[self.navigationController pushViewController:fvc animated=YES];
In the didFinishLaunchWithOptions method of my MyAppDelegate.m implementation I am creating a UINavigationController and initialising it with an instance of a UIViewController as the Root View Controller with the following code:
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: viewController1];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray arrayWithObjects: viewController1, viewController2, nil];
self.window.rootViewController = self.tabBarController;
My current understanding is that the initWithRootViewController variable should bind the UINavigationController object to viewController1. What am I doing wrong?!? Any thoughts, suggestions or pearls of wisdom would be greatly appreciated.
Many thanks,
-Munk
Upvotes: 0
Views: 62
Reputation: 21221
Yes initWithRootViewController
does bind the navigation, but then in the Tab Bar you should set the UINavigationController
and not the ViewController
itself
Change this line
self.tabBarController.viewControllers = [NSArray arrayWithObjects: viewController1, viewController2, nil];
to
self.tabBarController.viewControllers = [NSArray arrayWithObjects: nav, viewController2, nil];
Also you appear to have a typo here
[self.navigationController pushViewController:fvc animated=YES];
change it to
[self.navigationController pushViewController:fvc animated:YES];
Upvotes: 2