How to go back one view in UINavigationController?

后端 未结 3 590
庸人自扰
庸人自扰 2021-02-05 00:56

Is there a method to go back one view in the stack on a UINavigationController? Or to a view with a specific title?

相关标签:
3条回答
  • 2021-02-05 01:31

    Take a look at popViewControllerAnimated:.

    From the documentation: This method removes the top view controller from the stack and makes the new top of the stack the active view controller.

    Usage is something like:

    [aViewController popViewControllerAnimated:YES];
    
    0 讨论(0)
  • 2021-02-05 01:33

    Swift 3 version

    navigationController?.popViewController(animated: true)
    

    To pop to a specific view controller, you use:

    navigationController?.popToViewController(controller, animated: true)
    

    You will have to iterate through the list of view controllers first and check the title against what you're looking for and pass that to this method.

    0 讨论(0)
  • 2021-02-05 01:42

    I don't mean to be rude, but this is really well documented. A google search or even an Apple documentation search on UINavigationController will turn up exactly what you need. To programmatically pop the current view controller you use:

    [[self navigationController] popViewControllerAnimated:YES];
    

    To pop to a specific view controller, you use:

    [[self navigationController] popToViewController:controller animated:YES];
    

    You will have to iterate through the list of view controllers first and check the title against what you're looking for and pass that to this method.

    0 讨论(0)
提交回复
热议问题