在Swift中的Nav Controller中弹出2个视图控制器 [英] Pop 2 view controllers in Nav Controller in Swift
问题描述
我发现很多方法可以使用Objective-C在 UINavigationController
中弹回2 UIViewControllers
,但是当我尝试并切换到Swift它似乎没有工作。
I have found many ways to pop back 2 UIViewControllers
in UINavigationController
using Objective-C, however when I try and switch that over to Swift it doesn't seem to be working.
回弹到 UIViewController
的最佳方法是什么?
任何指导都将被赞赏
谢谢
What would be the best approach to pop back to UIViewController
?
Any guidance would be appreciated
Thanks
推荐答案
扩展我的评论,找到第二个最后一个视图控制器在viewControllers数组中,然后使用popToViewController来避免覆盖整个视图控制器堆栈。
Expanding on my comment, find the second last view controller in the viewControllers array and then use popToViewController to avoid overwriting the entire view controller stack.
示例(假设导航控制器有多个视图控制器):
Example (assumes the navigation controller has more than 1 view controller):
func backTwo() {
let viewControllers: [UIViewController] = self.navigationController!.viewControllers as [UIViewController]
self.navigationController!.popToViewController(viewControllers[viewControllers.count - 3], animated: true)
}
这篇关于在Swift中的Nav Controller中弹出2个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!