0

If I have some flow of my application like this..

navigation(vc1) --pushed--> vc2 --present--> navigation(vc3) --push--> vc4 --push--> vc5

how to dismiss to vc2 ?

  • maybe this is what you are looking for https://stackoverflow.com/questions/47322379/swift-how-to-dismiss-all-of-view-controllers-to-go-back-to-root – Havel Feb 21 '21 at 06:48

1 Answers1

0

You can use popToViewController:

Basic setup:

let nav = UINavigationController()
let vc1 = UIViewController()
vc1.title = "vc1"
let vc2 = UIViewController()
vc2.title = "vc2"
let vc3 = UIViewController()
vc3.title = "vc3"
let vc4 = UIViewController()
vc4.title = "vc4"
nav.viewControllers = [vc1,vc2,vc3,vc4]

Then pop to vc2 (which is at index 1 in the array):

let vcs = nav.viewControllers
nav.popToViewController(vcs[1], animated: true)
//OR, if you still have a reference to the view controller
nav.popToViewController(vc2, animated: true)
jnpdx
  • 45,847
  • 6
  • 64
  • 94