views:

45

answers:

2

Hi All,

I have a simple navigation based app which has a bunch fo forms in it, I have a method connected to a button that saves data when the button is tapped but I was wondering if I could call the same method when the back button is tapped in the navigation? Just incase a user fails to use the save button. If it is possible, how would I go about it?

thanks in advance!

A: 

Sure, in the viewWillDisappear: method of the UIViewController.

Tom Irving
+1  A: 

Your view controller's viewWillDisappear: method will be invoked when the back button is pressed (but also at other times), so that might be an option.

However, viewWillDisappear: will also be invoked if you present (say) a modalViewController, or push another viewController onto the navigation stack.

The only method I can think of that will be invoked only when the controller is popped from the navigation stack is the -dealloc method.

Dave DeLong
viewWillDisappear sounds like the way to go, there aren't going to be any views being pushed onto the stack once the users reach the edit pages, thanks a lot for the response!
iamthewit