Can i pop to Specific ViewController?

后端 未结 16 1883
我寻月下人不归
我寻月下人不归 2020-11-28 05:35

I am using navigation based application. I push First ViewController to Second ViewController and from Second ViewController to Third ViewController. Now I want to pop from

16条回答
  •  醉梦人生
    2020-11-28 06:14

    After lots of effort someone has created swift extension of back to a particular view controller in Swift 3.0.

    extension UINavigationController {
    
        func backToViewController(viewController: Swift.AnyClass) {
    
                for element in viewControllers as Array {
                    if element.isKind(of: viewController) {
                        self.popToViewController(element, animated: true)
                    break
                }
            }
        }
    }
    

    Method calling:

     self.navigationController?.backToViewController(viewController: YourViewController.self)
    

提交回复
热议问题