views:

82

answers:

1

I want to do some saving stuff when the user hits the back button on a navigation controller. Is this only possible by implementing

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    int index = [[self.navigationController.viewControllers] indexOfObject:[self.navigationController.visibleViewController]];
    if(viewController == [[self.navigationController.viewControllers] objectAtIndex:index-1])
        //saving code here

so the delegate gets called when it's about to show the previous view controller. Is there a more elegant way of knowing when the view controller will be popped?

and I can't use viewWillDisappear because there's a button that displays a UIImagePickerController, and I don't want the saving to be done then. Any thoughts?

A: 

You normally do things like that in the "viewWillDisappear:" method of a view controller.

Yes it also will activate if you are going forward, but you can flag that to let the method know if you meant to launch something else - and it's probably a good idea to save no matter what at that point anyway...

Kendall Helmstetter Gelner