Search code examples
iphoneobjective-cxcodeuinavigationcontrollerback-button

Back navigation in iphone application


Is there any way I can catch the event when I press the back button in my iPhone application? Right now I am using a button with image named Back on it and defining the action for that.

My client requires default back button pointing to previous screen so based on click event I should be able make it point to particular screen so that title of that screen is shown.

In short i need back button to show the title i required, is it possible?

Thanks in advance.


Solution

  • There are two ways to do this:

    1. Implement the back button yourself and call the UINavigationController's - (UIViewController *)popViewControllerAnimated:(BOOL)animated

    2. Subclass UINavigationController and implement - (UIViewController *)popViewControllerAnimated:(BOOL)animated to do your processing and pass on the call to super.

    3. As suggested in another answer UINavigationBarDelegate allows you to detect whether the button has been pressed if you handle the – navigationBar:didPopItem: message.