Search code examples
swiftuiviewcontrolleruinavigationcontroller

Dismiss all view controllers below current view controller swift


I am using a UINavigationController.

Lets say I have these stacks

VC1 -> VC2 -> VC3 
VC1 -> VC3
VC1 -> VC2 -> VC4 -> VC3

In all cases, how can I dismiss all VC's below VC3 when it is the current view controller.

VC3 is connected to a TabBarController if this make a difference.


Solution

  • From VC2, use setViewControllers method to push VC3 and to remove the rest,

    self.navigationController?.setViewControllers([VC3], animated: true)