Swift / iOS. Remove multiple view controllers from the navigation stack

This is what I want to do and I am not sure if this is the correct approach, so please give me advice on how to do this.

I have an initial VC with VC navigation, from that I press First VC, from that I press Second VC.

Next I introduce (from the NavigationController of Second VC) the Third VC.

And now I want to remove the first and second VC from the navigation stack.

After that I expect to get this kind of result: I fire the third VC and I see the Initial VC

How can I get this result?

+3


source to share


2 answers


You can remove the view controller from the function navigation stack:



navigationController?.viewControllers.removeAtIndex(*index of view controller you wanna remove*)

      

+5


source


You can switch back to the initial view controller by calling UINavigationController.popToRootViewController(animated: Bool)



+1


source







All Articles