【发布时间】:2020-08-05 19:29:37
【问题描述】:
我的层次结构看起来像这样:
VC 层次结构
- UITabBarController
1.1 ViewController 和 2 个容器视图
1.1.1。 UINavigationController
1.1.1.1。 UITableViewController
1.1.1.1.1 UITableViewController
1.2 ViewController 和 2 个容器视图
1.2.1。 UINavigationController
1.2.1.1。 UITableViewController
1.2.1.1.1 UITableViewController
想要的解决方案
我想在选择tabBar时拥有最深的VC PopToRoot。This post explains how
我已经设法在调试器中找到了正确的 VC,但是在编写代码来获取它时,Xcode 抱怨 Segmentation Fault 11
代码
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController ) -> Bool {
if tabBarController.selectedViewController === viewController {
if let nc = viewController.children.first(where: { $0.isKind(of: UINavigationController.self)}) as? UINavigationController {
if let handler = nc.children.first(where: { $0.isKind(of: TabBarReselectHandling.self )}) as? TabBarReselectHandling {
handler.handleReselect()
}
return true
}
只要我注释掉 if let handler 行,Xcode 就会显示错误:
An internal error occured. Source editor functionality is limited. Attempting to restore...
这一行适用于一个 tabBarItem,但不是全部,因为 VC 1.1 和 1.2 中的两个 containerViews 的顺序可能不同
let handler = viewController.children[1].children[1] as? TabBarReselectHandling
关于如何安全地找到我最深的 VC 有什么建议吗?
【问题讨论】:
标签: swift