如何将UINavigationController添加到呈现为Modal的UIViewController中

问题描述:

我的应用程序中有一个替代流程。该流程开始于我的firstViewController,然后在此查看呼叫我secondViewController这样的:如何将UINavigationController添加到呈现为Modal的UIViewController中

- (IBAction)PressButton:(id)sender { 

    SecondViewController *second = [[SecondViewController alloc] init]; 
    second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
    UINavigationController *nav = self.navigationController; 
    [nav presentViewController:second animated:YES completion:nil];        
} 

在我secondViewController我希望把我的thirdViewController。但它不工作我尝试这样的方式:

- (IBAction)pressButton:(id)sender { 

    ThirdViewController *tvc = [[ThirdViewController alloc] init]; 
    UINavigationController *nav = self.navigationController; 
    [nav pushViewController:tvc animated:YES]; 

}

当我按下的secondViewController没有任何按钮发生。

我在做什么错了?

我使用:

  • OSX 10.8.2
  • 的Xcode 4.6
  • 的iOS 6.1

需要出示导航控制器模态,和具有第二视图,该导航控制器的根。以及从拥有视图调用presentViewController而不是其父导航控制器。

- (IBAction)PressButton:(id)sender { 
     SecondViewController *second = [[SecondViewController alloc] init]; 
     second.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; 
     UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:second]; 
     [self presentViewController:navigationController animated:YES completion:nil];  
    } 
+0

工程就像一个魅力!谢谢 ! – Sebastian 2013-02-25 04:42:19

而是呈现只在第二个视图控制器,一定要提出一个附加导航控制器。

SecondViewController *secondViewController = [[SecondViewController alloc] init]; 

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:secondViewController]; 
[[self navigationController] presentViewController:navigationController animated:YES completion:nil]; 
+0

嗨亚伦,谢谢你的回答。不幸的是,当我这样做时,应用程序崩溃。 === >>>原因:'应用程序试图以模态方式呈现活动控制器。' – Sebastian 2013-02-25 01:40:48

+0

尝试将我的示例中的navigationController的名称更改为“secondNavigationController”或沿着这些行的内容。现在你要展示一个视图控制器,或者你的情况下是一个导航控制器,两次。 – 2013-02-25 03:17:26

如果您使用的故事板只需要点击源视图厦门国际银行,按Ctrl +拖动到目标(创建Segue公司),从弹出menu.Click选择模式新创建的连接上。然后在源视图控制器中为其添加一个名称[self performSegueWithIdentifier:@"Segue Name" sender:self];

如果您试图获取按钮以模式方式指引您访问其他页面,则可以进入故事板或xib文件。控制点击从该按钮到你想要去的视图控制器。然后弹出菜单会给你选择你想要使用什么类型的插座。希望这可以帮助