将导航控制器添加到viewcontroller,它是窗口的rootviewcontroller

时间:2013-06-24 16:58:25

标签: iphone ios6 uinavigationcontroller xib

我想添加导航控制器来查看控制器,它是窗口的rootviewcontroller。两个xib文件主要是window.xib和视图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文件。

1 个答案:

答案 0 :(得分: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;
}