我的主视图 Controller 是Tabbarcontroller
- 从选项卡栏导航到 (A) Viewcontroller (TabarViewcontroller -> A( View Controller )
- 从 A(Viewcontroller)我推送(B)Viewcontroller
- 来自 B(Viewcontroller)我现在(C)Viewcontroller
- 当我关闭 (c) Viewcontroller 时,我想显示 (A) Viewcontroller 或(主页)TabbarviewController
所以,我想首先关闭呈现的 View Controller ,然后弹出我之前推送的 Controller
这是我的导航流程
From Tabbarviewcontroller
1- let aVC = self.storyboard?.instantiateViewController(withIdentifier: "a") as! OrderListingViewController
self.navigationController?.pushViewController(aVC, animated: true)
From A viewcontroller
2- let bVC = self.storyboard?.instantiateViewController(withIdentifier: "b") as! OrderListingViewController
self.navigationController?.pushViewController(bVC, animated: true)
From B viewcontroller
let cVC = self.storyboard?.instantiateViewController(withIdentifier: "c") as! RejectOrderViewController
cVC.providesPresentationContextTransitionStyle = true
cVC.definesPresentationContext = true
cVC.modalPresentationStyle=UIModalPresentationStyle.overCurrentContext
self.tabBarController?.presentVC(cVC)
所以当我关闭时,从 C Viewcontroller 中我想显示 Tabbarviewcontroller 或 (A) ViewController
最佳答案
您必须忽略 ViewController C
通过以下方式。
self.presentingViewController
将给出前一个 View Controller 对象。
移动到 Root View Controller
let presentingVC = self.presentingViewController
self.dismiss(animated: true) {
presentingVC?.navigationController?.popToRootViewController(animated: false)
}
移至上一个 Controller
如果您需要以前的 View Controller 而不是 Root View Controller ,那么您只需使用 popViewController
let presentingVC = self.presentingViewController
self.dismiss(animated: true) {
presentingVC?.navigationController?.popViewController(animated: false)
}
移动到特定的 View Controller
let presentingVC = self.presentingViewController
self.dismiss(animated: true) {
if let destinationVC = presentingVC?.navigationController?.viewControllers.filter({$0 is <Your Destination Class>}).first {
presentingVC?.navigationController?.popToViewController(destinationVC, animated: false)
}
}
<Your Destination Class>
替换为您的目标类名称。
关于ios - 如何同时关闭并弹出到 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44669698/