为什么“window.rootViewController = self.navigationController”是Xcode 4 基于导航的应用程序需要吗?
为什么 didFinishLaunchingWithOptions 方法中需要以下行?
self.window.rootViewController = self.navigationController;
也就是说,请注意 Interface Builder 中的 MainWindow XIB 中已经存在导航控制器及其导航栏和其层次结构中的 RootViewController。
供参考的整个方法的副本是:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
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 customization after application launch.
// Add the navigation controller's view to the window and display.
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还没有在 MainWindow.xib 中完成一件事:将导航控制器的视图添加到窗口。
该线
就是这样做的。另一种选择(我们在 iOS 3 中编写的)是:
There is one thing you haven't yet done in MainWindow.xib: adding the nav controller's view to the window.
The line
does just that. The alternative (and what we wrote in iOS 3) is: