Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to go back one view in UINavigationController?

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

like image 830
Slee Avatar asked Jul 20 '10 18:07

Slee


People also ask

How do I pop navigation controller in Swift?

You can do it by selecting the View Controller in Storyboard editor and clicking Editor -> Embed In -> Navigation Controller. Also make sure that you have your Storyboard Entry Point (the arrow that indicates which view controller is presented first) either pointing to Navigation Controller or before it.


2 Answers

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.

like image 107
Matt Long Avatar answered Sep 30 '22 16:09

Matt Long


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]; 
like image 20
Tom Irving Avatar answered Sep 30 '22 17:09

Tom Irving