替换UINavigationController层次结构中的UIViewController [英] Replace a UIViewController in the UINavigationController hierarchy

查看:122
本文介绍了替换UINavigationController层次结构中的UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iPhone应用程序,它使用 UINavigationController 的标准实现进行应用程序导航。

I have an iPhone app which uses a standard implementation of UINavigationController for the app navigation.

我是试图找出一种方法来替换层次结构中的视图控制器。
换句话说,我的应用程序加载到 rootViewController ,当用户按下按钮时,应用程序将推送到 firstViewController 。然后用户按下另一个按钮将应用程序导航到 secondViewController 。再次使用导航到另一个视图控制器,thirdViewController。但是,我希望 thirdViewController 的BackButton弹回到firstViewController。

I am trying to figure out a way to replace a view controller in the hierarchy. In other words, my app loads into a rootViewController and when the user presses a button, the app pushes to firstViewController. Then the user pushes another button to navigate the app to secondViewController. Again the use navigates down to another view controller, thirdViewController. However, I want the BackButton of the thirdViewController to pop back to firstViewController.

基本上,当用户推送 thirdViewController 时,我希望它替换 secondViewController 在导航层次结构中。

Essentially, when the user pushes to thirdViewController, I would like it to replace secondViewController in the navigation hierarchy.

这可能吗?我知道它正在使用Three20,但我不是这种情况。不过,如果它可以在Three20中使用,那么肯定应该使用直接的SDK调用。有没有人有任何想法?

Is this possible? I know it is using Three20, but I'm not in this case. Nevertheless, if it's possible in Three20, then it certainly should be using straight SDK calls. Does anyone have any thoughts?

干杯,
Brett

Cheers, Brett

推荐答案

非常简单,当要推送第三个ViewController而不是做一个简单的 pushViewController 时这样做:

Pretty Simple, when about to push the thirdViewController instead of doing a simple pushViewController do this:

NSArray * viewControllers = [self.navigationController viewControllers];
NSArray * newViewControllers = [NSArray arrayWithObjects:[viewControllers objectAtIndex:0], [viewControllers objectAtIndex:1], thirdController,nil];
[self.navigationController setViewControllers:newViewControllers];

其中 [viewControllers objectAtIndex:0] [viewControllers objectAtIndex:1] 是你的rootViewController和你的FirstViewController。

where [viewControllers objectAtIndex:0] and [viewControllers objectAtIndex:1] are your rootViewController and your FirstViewController.

这篇关于替换UINavigationController层次结构中的UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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