I have found many ways to pop back 2 UIViewControllers
in UINavigationController
using Objective-C, however when I try and switch that over to Swift it doesn't seem to be working.
What would be the best approach to pop back to UIViewController
?
Any guidance would be appreciated
Thanks
You can dynamically pop multiple viewcontrollers in (swift 2.0)
I wrote an UIViewController extension (Swift 3+ ready)
You could use like this :
Usage :
Bonus dismiss to a specific viewcontroller
Usage :
Expanding on my comment, find the second last view controller in the viewControllers array and then use popToViewController to avoid overwriting the entire view controller stack.
Example (assumes the navigation controller has more than 1 view controller):
user5320485 answer in swift3
Swift 4 UINavigationController extension version of @Maximelc's answer:
I did a helper to make it easy:
For example, in your
ViewController
you can useNavigationHelper.back(number: 1, from: self)