Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to "pop" several View controllers in UINavigationController Stack?

In my app I'm implementing UINavigationController. There are several UIViewControllers that are being pushed in the stack.

When I reach the last one, I wish to have (upon a user action) all the UIViewControllers be popped except for the first UIViewController. How do I do that?

I understand how to pop the last one, but how do I instruct all the previous ones to disappear as well?

like image 338
Ohad Regev Avatar asked Jul 05 '11 09:07

Ohad Regev


People also ask

How do I pop two viewControllers at a time?

How do I pop two viewControllers at a time in Swift? There's also a setViewControllers(_:animated:) to include the pop animation. Alternatively you could find the second last view controller in the viewControllers array and then use popToViewController to avoid overwriting the entire view controller stack.

How to get current view controller in navigation controller?

You can access the navigation controller's array of view controllers through its viewControllers property. To access the root view controller, we ask for the first item of the array of view controllers.

What does popViewController do?

popViewController(animated:)Pops the top view controller from the navigation stack and updates the display.


1 Answers

You can try the popToRootViewControllerAnimated:, popToViewController:animated: and popViewControllerAnimated: messages of the UINavigationController class.

like image 190
phi Avatar answered Oct 19 '22 22:10

phi