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?
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.
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.
popViewController(animated:)Pops the top view controller from the navigation stack and updates the display.
You can try the popToRootViewControllerAnimated:
, popToViewController:animated:
and popViewControllerAnimated:
messages of the UINavigationController
class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With