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
Yes
initWithRootViewControllerdoes bind the navigation, but then in the Tab Bar you should set theUINavigationControllerand not theViewControlleritselfChange this line
to
Also you appear to have a typo here
change it to