一尘不染

如何在Swift中弹出特定的View Controller

swift

我使用Objective-C下面的代码弹出特定的代码ViewController

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

我该如何在Swift中做到这一点?


阅读 311

收藏
2020-07-07

共1个答案

一尘不染

尝试以下代码:

for controller in self.navigationController!.viewControllers as Array {
    if controller.isKind(of: ViewController.self) {
        self.navigationController!.popToViewController(controller, animated: true)
        break
    }
}
2020-07-07