以编程方式定义新的导航控制器订单/堆栈? [英] Programmatically defining a new navigation controller order/stack?

查看:140
本文介绍了以编程方式定义新的导航控制器订单/堆栈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 NavigationController ,其中嵌入了以下VC:VC1 - > VC2 - > VC3 - > VC4 - > VC5。我的问题是,当我从VC5中删除时(编辑完成后),我发送回VC3,但我想以编程方式将VC4和VC5从堆栈中删除,即当用户被送回VC3时,我想要返回 在 navagitionBar 中带你到VC2(而不是你真正来自的VC5)。

I have a NavigationController that the following VC's are embedded in: VC1 -> VC2 -> VC3 -> VC4 -> VC5. My problem is that when I segue from VC5 (after editing is completed), I send you back to VC3, but I want to programmatically throw VC4 and VC5 off the stack, i.e. when the user is sent back to VC3, I want "back" in the navagitionBar to take you to VC2 (and not VC5 where you really came from).

在IOS中出现了很多,你要编辑模型,然后将它们发送回tableView / Collection视图,但是由于编辑完成,你不要不希望在导航堆栈中编辑viewControllers,因为它太过混乱了UX。

This comes up a lot in IOS, where you want to edit the model, then send them back to the tableView/Collection view, but since editing is done, you don't want the editing viewControllers in the navigation stack anymore as its too confusing of UX.

在下面的屏幕截图中,右上角的VC是VC5:,它被重新引导回PinViewController(VC3) )via self.performSegueWithIdentifier(backToPins,sender:self)

In the screenshot below, the VC on the top right is VC5: which is segued back to the PinViewController (VC3) via self.performSegueWithIdentifier("backToPins", sender: self)

我该怎么做?

推荐答案

不要使用 segue 回来(pop)。

don't use segue to come back (pop).

你应该使用 popToViewController 并传递特定的 viewcontroller as弹出该视图控制器的参数。

you should use popToViewController and pass specific viewcontroller as argument to pop that viewcontroller.

例如,如果你想在第五个视图控制器中使用五个,那么你可以做类似下面的事情。你可以只从viewcontroller数组更改索引到不同的视图控制器。

for example if you want to go on 3rd view controller out of five then you can do something like below. you can just change index from viewcontroller array to go different view controller.

let viewControllers: [UIViewController] = self.navigationController!.viewControllers as [UIViewController];
self.navigationController!.popToViewController(viewControllers[viewControllers.count - 3], animated: true);

如果您使用segue,则表示您将新的viewcontroller添加(推送)到导航堆栈。在您的示例中,到达第5个视图后的堆栈就像是,

If you are using segue that means you add (push) new viewcontroller to navigation stack. in your example your stack after reaching 5th view is like,

VC1 - VC2 - VC3 - VC4 - VC5(堆栈顶部)

现在如果你继续回到VC3那么堆栈应该是这样的,

now if you performsegue to go back to VC3 then stack should be like this,

VC1 - VC2 - VC3 - VC4 - VC5 - VC3(堆栈顶部)

如果你弹出到VC3然后你的堆栈就像,

and if you pop to VC3 then your stack is like,

VC1 - VC2 - VC3(堆栈顶部)

所以流行的viewcintrollers回去不要使用 segue

so pop viewcintrollers to go back don't use segue

希望这将有助于:)

这篇关于以编程方式定义新的导航控制器订单/堆栈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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