Let's say I have four VCs in a stack: View1, View2, View3, and View4. Upon finishing with View4, I want to go back to View2 instead of popping to View3.
The code I currently use to accomplish this is:
let allViewControllers = self.navigationController?.viewControllers
for thisVC in allViewControllers!{
if thisVC.isKind(of: View2.self){
self.navigationController?.popToViewController(thisVC, animated: true)
}
}
The problem that I'm experiencing with this is I see the View3 animate by before eventually landing on View2. In other words, I press the button on View4 which calls the aforementioned code, then it pops to View3 briefly before then popping to View2. Is there any way to jump directly to View2 without seeing View3 in between?
In case it's relevant, here is the code I use to push View4 from View3
let vc = self.storyboard!.instantiateViewController(withIdentifier: "View3") as! View3ViewController
self.navigationController?.pushViewController(vc, animated: true)