0

我想将导航控制器添加到视图控制器,它是窗口的根视图控制器。两个xib文件主要是window.xib和view controller.xib文件。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

self.window.rootViewController = self.viewController;

[self.window makeKeyAndVisible];

return YES;
}

试过这个

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
// Override point for customization after application launch.

self.window.rootViewController = self.viewController;

self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];

 [self.window addSubview:self.navController.view];

[self.window makeKeyAndVisible];
return YES;
}

但我认为不起作用,因为涉及两个 xib 文件。

4

1 回答 1

0

您没有正确设置根视图控制器。你虽然很接近。这是正确的代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
 {
// Override point for customization after application launch.

self.navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];


self.window.rootViewController = self.navController;

[self.window makeKeyAndVisible];
return YES;
}
于 2013-06-24T17:56:36.697 回答