How can I call a method when the back button on a UINavigationController is pressed. I need to be able to call a method before the previous view is displayed. Is this possible? If so please can someone advise on how to do this?
How can I call a method when the back button on a UINavigationController is
Share
A fast solution is to add an implementation for the viewWillDisappear: method. It will be triggered as soon as the viewController will disappear in response to the back button pression.
Another solution is to add a custom responder to the back button. You can modify your viewController’s init method as follow:
and then you can use a selector method as the following. Be sure to dismiss correctly the viewController, otherwise your navigation controller won’t pop as wanted.