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
  • 49,286
  • 91
  • 294
  • 502

2 Answers2

5

You can try

for vc in self.navigationController!.viewControllers {
   if let myVC = vc as? VCName {
     self.navigationController?.popToViewController(myVC, animated: true)
   }
}
Sh_Khan
  • 93,445
  • 7
  • 57
  • 76
5

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

self.navigationController?.popToViewController(self.navigationController!.viewControllers[1], animated: true)
Retterdesdialogs
  • 3,120
  • 1
  • 20
  • 39