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

后端 未结 4 1395
长情又很酷
长情又很酷 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:21

    Instead of doing a generic popViewControllerAnimated: call, use popToViewController:animated:. You could detect if the user has deleted all of the rows in which case, do something like this (otherwise just pop one view controller):

    let viewControllers: [UIViewController] = self.navigationController!.viewControllers as [UIViewController];
    self.navigationController!.popToViewController(viewControllers[viewControllers.count - 2], animated: true);
    

提交回复
热议问题