How can I pop specific View Controller in Swift

前端 未结 16 2944
一生所求
一生所求 2020-12-08 02:21

I used the Objective-C code below to pop a specific ViewController.

for (UIViewController *controller in self.navigationController.         


        
16条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 02:49

    simple and best solution without force unwrapped is

    if let vc = navigationController.viewControllers.filter({$0 is YourViewController}).first as? YourViewController {
                self.navigationController.popToViewController(vc, animated: true)
                }
    

提交回复
热议问题