Mahesh Cheliya Mahesh Cheliya - 1 year ago 143
Swift Question

How can I pop specific View Controller in Swift

I used below code for

for pop specific view controller:

for (UIViewController *controller in self.navigationController.viewControllers) {
if ([controller isKindOfClass:[AnOldViewController class]]) {
//Do not forget to import AnOldViewController.h
[self.navigationController popToViewController:controller

How can I do that in Swift?

Answer Source

try following code.

for controller in self.navigationController!.viewControllers as Array {
            if controller.isKindOfClass(ViewController) {
             self.navigationController?.popToViewController(controller as UIViewController, animated: true)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download