I want to pop to the third view on the navigation stack back to the first view.
I know how to pop one view at once:
[self.navigationController popViewControllerAnimated:YES];
But how do I do two at once?
Thanks...
I want to pop to the third view on the navigation stack back to the first view.
I know how to pop one view at once:
[self.navigationController popViewControllerAnimated:YES];
But how do I do two at once?
Thanks...
you can pop back to the root view controller
or, if the view you want to pop to isn't the first one, you'll need to pop again in your previous view's viewWillAppear
In Swift 3, you can pop one, two or more viewcontrollers from navigation controller like that
Here FromWhereYouWantToGoController is destination controller. Hope it helps.
Here are two
UINavigationController
extensions that can solve your problem. I would recommend using the first one that pops to aUIViewController
of a specific class:and use it like this:
Here's a little function I'm using to go back X ViewControllers:
You can pass the initial view controller (the one you want to come back to) and then call this line in the last view:
L.
I didn't see this answer in here. If you only want to pop a few (not all the way to the root), you can just iterate through self.navigationController.viewControllers checking for class types, or if you have a reference use that: