How to press "Back" button in UINavigationController programmatically

Timur Mustafaev picture Timur Mustafaev · Oct 4, 2011 · Viewed 33.3k times · Source

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?

Answer

Mann picture Mann · Oct 4, 2011

Simply use

[self.navigationController popViewControllerAnimated:YES]

from FriendsDetailedViewController. Your view will be popped out i.e. the behavior of back button