问题描述
我找到了很多方法来使用 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 appreciatedThanks
推荐答案
扩展我的评论,在 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)
}
Objective-C
NSArray *viewControllers = [self.navigationController viewControllers];
[self.navigationController popToViewController:viewControllers[viewControllers.count - 3] animated:YES];
这篇关于在 Swift 中的 Nav Controller 中弹出 2 个视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!