本文介绍了如何将UINavigationController添加到模态形式的UIViewController中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中还有其他流程.此流程从我的firstViewController开始,然后在此视图中像下面这样调用我的secondViewController:

I have an alternative flow in my app. This flow starts in my firstViewController, then in this view a call my secondViewController like this:

- (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.但是我试过这种方法不起作用:

In my secondViewController I want to push my thirdViewController. But it is not working I tried this ways:

- (IBAction)pressButton:(id)sender {

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

}

当我按下secondViewController的按钮时,没有任何反应.

When I press the button of secondViewController nothing happens.

我做错了什么?

我正在使用:

  • OSX 10.8.2
  • Xcode 4.6
  • iOS 6.1

推荐答案

您必须以模态显示导航控制器,并将第二个视图作为该导航控制器的根.除了从拥有的视图而不是其父导航控制器中调用presentViewController之外.

You must present the navigation controller modally, and have the second view as the root of that navigation controller. As well as calling presentViewController from the owning view not its parent navigation controller.

- (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];    
    }

这篇关于如何将UINavigationController添加到模态形式的UIViewController中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 10:27