Can i pop to Specific ViewController?

后端 未结 16 1897
我寻月下人不归
我寻月下人不归 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 05:54

    Swift 4 version

    if let viewController = navigationController?.viewControllers.first(where: {$0 is YourViewController}) {
          navigationController?.popToViewController(viewController, animated: false)
    }
    

    You may specify another filter on .viewControllers.first as per your need e.g lets say if you have same kind of view controllers residing in the navigation controller then you may specify an additional check like below

      if let viewController = navigationController?.viewControllers.first(where: {
            if let current = $0 as? YourViewController {
                 return current.someProperty == "SOME VALUE"
            }
           return false } ) {
                navigationController?.popToViewController(viewController, animated: false)
       }
    

提交回复
热议问题