How does navigationController get it’s topViewController set in this code (from CoreDataBooks example)? I assume some mapping in the NIB file, however I can’t quite prove how things work here myself by reviewing this code and the NIB file in Interface Builder.
The source code for the example is available here.
Is someone able to explain out the topViewController is set in this application such at in the CoreDataBooksAppDelegate.m “applicationDidFinishLaunching” method, an instance of RootViewController is obtained? I’m guessing the explanation may revolve around how Interface Builder & the NIB file are handled…
- (void)applicationDidFinishLaunching:(UIApplication *)application {
RootViewController *rootViewController = (RootViewController *)[navigationController topViewController]; // <=== HOW DOES THIS WORK
rootViewController.managedObjectContext = self.managedObjectContext;
// Configure and show the window
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
}
It seems to be set up in the MainView.xib file. The navigation controller has inside it a view controller set to the class RootViewController.