I want to have a method called when the user clicks the back button in a navigation bar.
I know its possible to create my own back button with an action attached and use that in the navigation bar. But I don’t want to do this – I don’t have the artwork for such a button (and I tried using Apple’s own navigation button that I got after somebody posted online an unpacking of an iPhone’s artwork, but it doesn’t look right, and even if it does then it won’t match if I change the color of the navigation bar).
I also know its possible to look at the list of controllers in the stack in viewWillDisappear: but I’m navigating within a UIWebView where this won’t apply when nested pages are involved (actually what I’m trying to do is call [self.webView.goBack] in this situation instead of the UIWebView be popped off the stack).
So is there anyway for me to get a method to be called when the user clicks the navigation bar default back button?
TIA
Short answer no. The back button is private section of UINavigationBar.
It is possible that by subclassing UINavigationBar you may be able to access it but I doubt it.
Its important to note that even when you replace the leftBarButtonItem it is never a “back” button at that point but rather just another button that could possible send the user to a previous page.
If you want a “back” button that does your own method you need to go through the effort of making it the way everyone else does using custom graphics. It can be made to match the original back button you just have to put in the work.