How to press "Back" button in UINavigationController programmatically

Here is the swift method

if let navController = self.navigationController {
    navController.popViewControllerAnimated(true)
}

If by pressing "Back" button you mean just to go to the previous view controller, you can just call:

[self.navigationController popViewControllerAnimated:YES];

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 returns nil if there is nothing to pop.


Swift 5

 self.navigationController?.popViewController(animated: true)

Usage in a code snippet:

func unwindViewController() {
    self.navigationController?.popViewController(animated: true)
}