How can I pop specific View Controller in Swift

前端 未结 16 2962
一生所求
一生所求 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 03:00

    extension UINavigationController {
        func popBack(to vc: AnyClass, animated: Bool = true) {
            guard let elementFound = (viewControllers.filter { $0.isKind(of: vc) }).first else {
                fatalError("cannot pop back to \(vc) as it is not in the view hierarchy")
            }
            self.popToViewController(elementFound, animated: animated)
        }
    }
    

提交回复
热议问题