How to pop view controller to one of the previous view controllers in swift?

后端 未结 4 1397
长情又很酷
长情又很酷 2020-12-15 05:46

I have been trying to pop my view controller to one of previous view controllers in my view stack. Assume that, There are firstVC, secondVC, thirdVC and fourthVC

4条回答
  •  北海茫月
    2020-12-15 06:23

    If you want to pop to a specific view control and dont know the count to go back you can use this:

     let viewControllers: [UIViewController] = self.navigationController!.viewControllers as! [UIViewController];
    
            for aViewController in viewControllers {
                if(aViewController is ViewControllerYouWantToGoTo){
                     self.navigationController!.popToViewController(aViewController, animated: true);
                }
            }
    

提交回复
热议问题