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;
}
4

1 回答 1

7

在 MainWindow.xib 中您还没有完成一件事:将导航控制器的视图添加到窗口。

线

self.window.rootViewController = self.navigationController;

就是这样做的。替代方案(以及我们在 iOS 3 中编写的内容)是:

[self.window addSubview:self.navigationController.view];
于 2011-04-23T11:49:15.207 回答