Programmatically call navigation controller back button on iOS

Viewed 73960

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?

5 Answers

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

[navigationController popViewControllerAnimated:YES];

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.

You should call

popViewControllerAnimated:

which is the opposite of adding view controllers with pushViewController:animated:

Related