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?
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.
The gesture recognizer responsible for popping the top view controller off the navigation stack.
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];
Here is the swift method
if let navController = self.navigationController {
navController.popViewControllerAnimated(true)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With