I am working on an iPhone application. Application has a navigation bar at the top. I have two views say “View1” and “View2”. When you push “View2” view controller the navigation bar shows a back button with the title of the “View1” so you can go back to view1.
Now my question is which event is fired when you click that button? Also is it possible to change the text of that back button in navigation bar?
Any help will be greatly appreciated?
Thanks
There’s no specific event you can get just for that back button. You can use various
viewWillAppear:,viewWillDisappear:, etc. methods instead. eg:Note that the booleans wentToSubscreen and goingToSubscreen should be set up as named. If you are pushing another view onto the navigation controller on top of View2, you should set goingToSubscreen to YES so that it doesn’t do the important stuff. Conversely, you should set wentToSubscreen to YES on View1 after pushing View2, so that when it appears again, it’s after coming back from that screen that something interesting happens, and not when View1 initially appears.
Edit:
As of iOS 5.0, I believe there are built-in properties for this.
isBeingDismissedis set toYESduringviewWillDisappear:andviewDidDisappear:in the case that you press the back button. For reference, the properties you can check are:As for changing the title of the back button, the property belongs to the previous view’s back button item:
or:
Your third option is to use a custom button to replace the back button. It will let you specify your own method to call so you don’t need to use
-viewWillDisappear:, but doing this will show the button as a rectangle instead of a back arrow button. This button goes on View2 instead of View1: