Redirect User to Specific ViewController - Swift 4

Viewed 979

I'm trying to redirect users to the correct page after deletion of the place.

enter image description here

navigationController?.popToRootViewController(animated: true)

This will work, if I want to redirect to the root.

navigationController?.popViewController(animated: true)

This will work if I want to redirect to the previous

BUT in my case, I want to redirect to a specific page that not the root or the previous one.

How would one go about and do something like this in iOS ?

2 Answers

You can try

for vc in self.navigationController!.viewControllers {
   if let myVC = vc as? VCName {
     self.navigationController?.popToViewController(myVC, animated: true)
   }
}

If you now the position in your stack you can also use

self.navigationController?.popToViewController(self.navigationController!.viewControllers[1], animated: true)
Related