我的场景
UITabbar ( UINavigation(page1) -push-> page2 -push-> page3 -present- > page4 )
从我的功能中,我留在 page4 并想将其关闭并弹出到根目录( page1 )但是当我得到 presentingViewController 它返回UITabbarController
不是我的UINavigationBarController
我现在的代码。
self.dismiss(animated: true) { [weak self] in
guard let topVc = self?.presentingViewController else { return }
if let destinationVC = topVc.navigationController?.viewControllers.filter({$0 is Page1ViewController}).first {
topVc.navigationController?.popToViewController(destinationVC, animated: true)
}
}
在我将 UITabbar 添加到我的流程之前,我的代码正在运行。
有人可以帮助我或向我解释根本原因吗?谢谢你的帮助。
更新 现在我找到了一个解决方案,但我认为这还不够好。
self.viewController.dismiss(animated: true) {
guard let topVc = Tools.getTopViewController(),
let tabBarVc = topVc as? MainTabBarController,
let nav = tabBarVc.selectedViewController as? BaseNavigationBarController else { return }
if let destinationVC = nav.viewControllers.filter({$0 is WalletViewController}).first {
nav.popToViewController(destinationVC, animated: true)
}
}