UINavigationBarDelegate
is probably the closest you can get to detecting whether the button has been pressed if you handle the – navigationBar:didPopItem:
message.
This will be called either when the back button is pressed or when your code pops the view off the navigation controller stack itself. If your code is popping views manually then it should be trivial to set up a flag to indicate when your code initiated a pop and therefore you can determine when the back button was tapped
In your UINavigationBarDelegate implementation create a boolean property such as poppedInCode
which you set to true just before your code performs a pop and implement the delegate like:
- (void) navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item
{
if (!self.poppedInCode) {
// back button was tapped
}
// set to false ready for the next pop
self.poppedInCode = FALSE;
}
This has the advantage over the currently accepted answer in that it doesn't require subclassing of components that Apple's documentation says that you shouldn't be subclassing. It also retains all the behaviour of the built-in back button without you having to rewrite it.