Why does changing the below code from the Old to New entry fix the following problem.
Code:
// OLD Entry - Did not work
//[self.window addSubview:navigationController.view];
// NEW Entry - Fixed it
self.window.rootViewController = self.navigationController;
Problem when I use Old Code:
I'm using a UINavigationController and have a "mainView" UITableViewController and then a 2nd level view I push onto the stack, let's call it "detailedView" UITableViewController.
Navigating normally back and forward from main to details works fine
BUT when automatically launch on startup into the 2nd view (as I save state) I get to the 2nd view OK, however the TOOLBAR BUTTONS do NOT appear at the bottom of the 2nd view in this case. When I go back to main page (via UINavigationController standard arrangements), and then then select the row in the UITableView, and go back into the same view again the toolbar items appear fine.
Couldn't track this down but finally through trial and error I noted this change in code (see above) in the appDelegate (of all places) seems to fix the issue.
Any ideas?
EDIT: For completeness here is the full method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
RootViewController *rootViewController = (RootViewController *)[navigationController topViewController];
NSManagedObjectContext *context = [self managedObjectContext];
if (!context) {
abort(); // TODO: Do better job here than abort
}
rootViewController.managedObjectContext = context;
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
EDIT 2: Oh, I do have a NIB file and have the root view controller/window setup in interface builder - so I'm wondering if I'm mixing a NIB and programmatic approach up here perhaps which might cause problems?
EDIT 3: Also noted that the following didFinishLaunchingWithOptions code worked when I added the "self.window.rootViewController = self.navigationController" line. That is without this line (which is what the coredatabooks example does) I get the issue.
RootViewController *rootViewController = (RootViewController *)[navigationController topViewController];
rootViewController.managedObjectContext = self.managedObjectContext;
self.window.rootViewController = self.navigationController; // WORKS WHEN I ADD THIS LINE IN FOR SOME REASON???
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
return YES;