如何将navigationViewController添加到UIViewController?
- (void)applicationDidFinishLaunching:(UIApplication *)application {
loginViewController *vc1=[[loginViewController alloc]initWithNibName:@"login" bundle:[NSBundle mainBundle]];
rootViewController* vc2 = [[[rootViewController alloc] init] autorelease];
UINavigationController* navController = [[[UINavigationController alloc]
initWithRootViewController:vc2] autorelease];
NSArray* controllers = [NSArray arrayWithObjects:vc1,navController, nil];
//loginViewController.viewControllers = controllers;
[window addSubview:[self.loginController view]];
// Override point for customization after application launch
[window makeKeyAndVisible];
}
我坚持这个。需要一些帮助...
答案 0 :(得分:0)
如果我理解正确,你应该使用
[window addSubview:[self.navController view]];
然后你可以发送push / pop消息到self.navigationController来管理navigationController堆栈的内容。
答案 1 :(得分:0)
最简单的方法是在设置navController时更改init。此外,您需要保留navController,可能作为应用委托的成员变量:
//in your header file:
....class definition
UINavigationController *_navigationController;
....
//in your implementation file:
_navigationController = [[UINavigationController alloc] initWithRootViewController: rootViewController];
//optional: if you want to start off 'one level in' to your navigation stack:
[_navigationController pushViewController: vc1 animated: NO];
[window addSubview _navigationController.view];