Search code examples
iphoneobjective-ciosuiviewcontrolleruinavigationcontroller

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?


Solution

  • 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.