How to press "Back" button in UINavigationController programmatically
I have a UIViewController
called FriendsViewController
inside a UINavigationController
. And a second UIViewController
called FriendsDetailedViewController
. When navigating from the first view controller to the second, I want to programmatically press the Back
button when needed. How to do this?
Simply use
[self.navigationController popViewControllerAnimated:YES]
from FriendsDetailedViewController. Your view will be popped out i.e. the behavior of back button.
Note that it returns
UIViewController
on normally, and returnsnil
if there is nothing to pop.
If by pressing "Back" button you mean just to go to the previous view controller, you can just call:
[self.navigationController popViewControllerAnimated:YES];