Search code examples
iosobjective-cstoryboarduistoryboardback

Adding control method(s) to button created in storyboard ?


I'm trying to add some finer control to the Storyboard controller and I hit a blockage with the back button.

I have a basic Storyboard with push transition. I want to be able to catch when the user presses on the back button (the one generated automatically) and decid if I want the view to go back or not.

The scenario is to show a message to the user asking if he wants to go back warning him that he is going to lose his work if he does,

Sounds simple, yet I can't find how to do it.

Any ideas


Solution

  • You don't get any sort of message by default when the back button is pressed. If you want to provide this sort of functionality, you have two options:

    1) Provide a custom back button and set it as the leftNavigationItem of your UIViewController's navigation bar

    2) Subclass UINavigationController and override a method such as popToRootViewController:animated: