My home viewcontroller is Tabbarcontroller
So, I want to first dismiss presented viewcontroller and then I want to pop my previous pushed controller
Here is my navigation flow
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)
so from C Viewcontroller when i dismiss i want to show Tabbarviewcontroller or (A) ViewController
You have to dismiss the ViewController C
in the following way.
self.presentingViewController
will give the previous view controller object.
Move to Root view controller
let presentingVC = self.presentingViewController
self.dismiss(animated: true) {
presentingVC?.navigationController?.popToRootViewController(animated: false)
}
Move to previous controller
If you need to previous view controller instead of root view controller then you have to just to a popViewController
let presentingVC = self.presentingViewController
self.dismiss(animated: true) {
presentingVC?.navigationController?.popViewController(animated: false)
}
Move to a specific 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>
replace with your destination class name.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With