从第一个视图调用第二个视图

时间:2011-12-07 06:59:20

标签: iphone ios

我想从我当前的视图中调用secondview,但有人建议此代码无法正常工作

UINavigationController *nav=[[UINavigationController alloc] initWithNibName:@"Second" bundle:[NSBundle mainBundle]];
[nav pushViewController:@"Second" animated:YES];

3 个答案:

答案 0 :(得分:2)

为什么要将NSString推到UINavigationController?我想你想要的是:

SecondView * vc = [[SecondView alloc] initWithNibNamed:@"SecondView"];
[self.navigationController pushViewController:vc animated:YES];
[vc release];

希望有帮助!

答案 1 :(得分:1)

您可以将presentModalViewController用于第二个视图。

希望这会对你有所帮助。

[self.navigationController presentModalViewController:SecondView animated:YES];

答案 2 :(得分:1)

  1. 如果是你的rootViewController,我建议你将naviagtionbar初始化放在你的application:didFinishLaunchingWithOptions:中。您可以使用rootViewController启动它,如下所示:

    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:firstViewController_1];
    self.window.rootViewController = nav;
    [nav release];
    
  2. 在视图控制器中推送其他视图(例如您的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];