2

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 ?

code-8
  • 54,650
  • 106
  • 352
  • 604

2 Answers2

5

You can try

for vc in self.navigationController!.viewControllers {
   if let myVC = vc as? VCName {
     self.navigationController?.popToViewController(myVC, animated: true)
   }
}
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87
5

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

self.navigationController?.popToViewController(self.navigationController!.viewControllers[1], animated: true)
Retterdesdialogs
  • 3,180
  • 1
  • 21
  • 42