How to pop from one view controller to another view controller

前端 未结 8 1325
北荒
北荒 2021-01-31 09:53

Using iOS I Have 15 ViewControllers now I want to pop from one ViewController to another View Controller.

I am using this code:

SecondViewController *Sec         


        
相关标签:
8条回答
  • 2021-01-31 10:30

    You can't pop to a new view controller (like you do with your secondViewController example).

    When using a UINavigationController you

    Add Controller to the stack with:

    [self.navigationController pushViewController:<yournewViewController> animated:YES];
    

    Pop to the previous one with :

    [self.navigationController popViewControllerAnimated:YES];
    

    Pop to a previous controller in the stack (Must have been pushed before) :

    [self.navigationController popToViewController:<ViewControllerToPopTo> animated:YES];
    

    Go back to the root Controller with

    [self.navigationController popToRootViewControllerAnimated:YES];
    
    0 讨论(0)
  • 2021-01-31 10:35

    For Swift 3.0, use filter:

    let desiredViewController = self.navigationController!.viewControllers.filter { $0 is YourViewController }.first!
    self.navigationController!.popToViewController(desiredViewController, animated: true)
    
    0 讨论(0)
提交回复
热议问题