I am using the storyboard
for my app which is using UINavigationController
. I would like to add a confirmation dialog to the default back button so the user does not log out accidentally. Is there some way to do this? I have found that I cannot simply access the back button when it has be automatically created by the UINavigationController
.
Any ideas?
Unfortunately, you can't intercept the back button in this way. The closest facsimile is to use your own UIBarButtonItem
set to the navigationItem.leftBarButtonItem
and set an action to display your alert etc. I had a graphic designer create button images that look like the standard back button.
As an aside, I needed to intercept the back button for a different reason. I urge you to reconsider this design choice. If you are presenting a view where users can make changes and you want them to have the choice to save or cancel IMHO it's better to use 'Save' and 'Cancel' buttons vs a back button with an alert. Alerts are generally annoying. Alternatively, make it clear that the changes your users are making are committed at the time they make them. Then the issue is moot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With