Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically call navigation controller back button on iOS

In a UINavigationController-based iPhone app, in a method I would like to perform the programmatic equivalent of the back button being pressed and going back a view.

i.e. automatically press the Jobs button as seen here:

Navigation Controller image

Is there a generic iOS call I can make, or is more information required?

like image 514
oberbaum Avatar asked Jan 21 '10 08:01

oberbaum


People also ask

How do I make a back button in Swift?

Back-button text is taken from parent view-controller's navigation item title. So whatever you set on previous view-controller's navigation item title, will be shown on current view controller's back button text. You can just put "" as navigation item title in parent view-controller's viewWillAppear method.


2 Answers

UINavigationController's -popViewControllerAnimated: method should do what you want:

[navigationController popViewControllerAnimated:YES]; 
like image 77
Steve Harrison Avatar answered Sep 20 '22 09:09

Steve Harrison


Assuming you don't actually want to PRESS the button programmatically, but simply copy the outcome of pressing the button, you should tell the navigation controller to pop the current view controller.

[self.navigationController popViewControllerAnimated:YES];

This will remove it from the stack, and return you to the previous view controller.

like image 40
Kevin Elliott Avatar answered Sep 19 '22 09:09

Kevin Elliott