I want to go back two ViewControllers rather than one when I click the back button on the NavigationController.
override func viewWillDisappear(_ animated: Bool)
{
super.viewWillDisappear(animated)
if self.isMovingFromParent
{
let vc = self.navigationController?.viewControllers[1] as! MyViewController
self.navigationController?.popToViewController(vc, animated: false)
}
}
This works almost the way that I want it to. Changing self.navigationController?.viewControllers[1] lets me go to any ViewController in the stack. The only issue I have is that it always briefly displays the top most viewController briefly before going directly to the ViewController that I have popped to. How do I stop it from displaying the intermediate ViewController?
My problem is:
VC[0] → VC[1] → VC[2] → VC[3]
From 3 I want to go back to 1 directly without it having to display 2. I want to do this from the NavigationController back button.
If you have a viewController in stack you can go back to it by using the class name.