Description
I have a Tab Bar Controller with a navigation controller tab. The first and default tab is called "NowViewController". So in my AppDelegate's application:didFinishLaunchingWithOptions
I have the following:
// Set up MainWindow
NowViewController *nowViewController = [[[NowViewController alloc] initWithNibName:@"NowViewController" bundle:nil] autorelease];
nowViewController.context = [self managedObjectContext];
self.tabBarController.selectedViewController = nowViewController;
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
I ne开发者_高级运维ed to pass the Core Data's managed object context which is why I instantiate a NowViewController object.
Now in my MainWindow.xib, I simply have the Navigation Controller set as follows:
Problem
When launching the app, I get an empty page with the NewsViewController. When I click on the "Now" tab, I will then get a Navigation Bar that says "Root View Controller" when in fact it should say "Now". I already have self.title = @"Now"
in the NowViewController's ViewDidLoad
method.
Any ideas why I am getting this kind of problem?
Thank you!
FIXED
I just changed my AppDelegate's line of code posted above to:
NowViewController *nowViewController = (NowViewController *) [self.navigationController topViewController];
nowViewController.context = [self managedObjectContext];
self.window.rootViewController = self.tabBarController;
[self.window makeKeyWindow];
I would really appreciate though if someone would explain exactly this line of code:
NowViewController *nowViewController = (NowViewController *) [self.navigationController topViewController]
精彩评论