有条件地使用UINavigatonController在iOS 5应用程序中跳过UIViewController [英] Conditionally skipping a UIViewController in an iOS 5 app with UINavigatonController

查看:92
本文介绍了有条件地使用UINavigatonController在iOS 5应用程序中跳过UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的iOS应用程序中,一个接一个地有三个 UIViewController ,我们想根据某些条件跳过中间的一个,直接从第一个到第三个。但是,用户应该可以通过第三个控制器上的后退按钮返回第二个。

In our iOS application with three UIViewControllers one after another, we would like to skip the middle one based on some condition and go directly from first to third. However, the user should be able to come back to the second one via the "Back" button on the third controller.

我试过 [self performSegueWithIdentifier:@segueIdsender:sender]; from viewDidLoad viewWillAppear 但是这个如调试日志所示,破坏导航栏。从 viewDidAppear 调用此代码可以正常工作,但是第二个视图已经显示,这是我首先想要避免的。

I tried [self performSegueWithIdentifier:@"segueId" sender:sender]; from viewDidLoad, viewWillAppear but this corrupts the navigation bar as indicated by the debug log. Calling this code from viewDidAppear works fine, but then the second view is already displayed, which is what I was trying to avoid in the first place.

我也试过 [self.navigationController pushViewController:vc animated:NO]; 但结果同样是损坏的导航吧,即使这次调试日志没有这样的条目。

I also tried [self.navigationController pushViewController:vc animated:NO]; but the result is similarly corrupted nav bar, even though this time debug log does not have such entries.

这样做的支持方式是什么(如果可能的话)?

What would be the supported way of doing this (if it is at all possible)?

目标是带有iOS 5.1的iPhone4,开发环境是Xcode 4.3。

The target is iPhone4 with iOS 5.1, and the dev environment is Xcode 4.3.

推荐答案

我在应用中使用以下代码。完全按预期工作。

I use the following code in an app. Works exactly as expected.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    SecondViewController *secondVC = [self.storyboard instantiateViewControllerWithIdentifier:@"DetailViewController"];
    if (indexPath.row == 0) {
        // skip second vc
        ThirdViewController *thirdVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ThirdViewControllerViewController"];
        [self.navigationController pushViewController:secondVC animated:NO];
        [self.navigationController pushViewController:thirdVC animated:YES];
    }
    else {
        // push second vc
        [self.navigationController pushViewController:secondVC animated:YES];
    }
}

这篇关于有条件地使用UINavigatonController在iOS 5应用程序中跳过UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆