我想从我当前的视图中调用secondview,但有人建议此代码无法正常工作
UINavigationController *nav=[[UINavigationController alloc] initWithNibName:@"Second" bundle:[NSBundle mainBundle]];
[nav pushViewController:@"Second" animated:YES];
答案 0 :(得分:2)
为什么要将NSString
推到UINavigationController
?我想你想要的是:
SecondView * vc = [[SecondView alloc] initWithNibNamed:@"SecondView"];
[self.navigationController pushViewController:vc animated:YES];
[vc release];
希望有帮助!
答案 1 :(得分:1)
[self.navigationController presentModalViewController:SecondView animated:YES];
答案 2 :(得分:1)
如果是你的rootViewController,我建议你将naviagtionbar初始化放在你的application:didFinishLaunchingWithOptions:
中。您可以使用rootViewController启动它,如下所示:
UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:firstViewController_1];
self.window.rootViewController = nav;
[nav release];
在视图控制器中推送其他视图(例如您的FirstViewController.m):
SecondViewController * secondViewController_2 = [[[NSBundle mainBundle] loadNibNamed:@"SecondViewController" owner:self options:nil] lastObject];
// Or: SecondViewController * secondViewController_2 = [[SecondViewController alloc] init...] autorelease];
[self.navigationController pushViewController:secondViewController_2 animated:YES];