我使用下面的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中做到这一点?
解决方法
请尝试以下代码:
for controller in self.navigationController!.viewControllers as Array { if controller.isKind(of: ViewController) { self.navigationController!.popToViewController(controller,animated: true) break } }