why is "window.rootViewController = self.navigationController" needed in Xcode 4 Navigation Based App?
Why is the following line needed within the didFinishLaunchingWithOptions method?
self.window.rootViewController = self.navigationController;
That is, noting there is already in Interface Builder, in the MainWindow XIB, the navigation controller with it's navigation bar and RootViewController within it's hierarchy.
Copy of whole method for reference is:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customizat开发者_如何学Pythonion after application launch.
// Add the navigation controller's view to the window and display.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
There is one thing you haven't yet done in MainWindow.xib: adding the nav controller's view to the window.
The line
self.window.rootViewController = self.navigationController;
does just that. The alternative (and what we wrote in iOS 3) is:
[self.window addSubview:self.navigationController.view];
精彩评论