Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which method is called when back button clicked in navigation controller?

I want to save DB when the back button clicked in navigation controller.

so I would insert code in method.

What method is called when back button clicked in navigation controller?

like image 426
석진영 Avatar asked Oct 31 '11 01:10

석진영


2 Answers

To do what you asked, look at the UINavigationControllerDelegate protocol, namely the method:

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated 

when the viewController argument is no longer your view controller then you should save.

However, doing so on viewWillDisappear: might be a better (and much simpler) idea.

like image 108
Benjie Avatar answered Nov 16 '22 13:11

Benjie


Maybe it's not appropriate use, but that worked for me. Don't forget to set UINavaigationController delegate.

- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
                                   animationControllerForOperation:(UINavigationControllerOperation)operation
                                                fromViewController:(UIViewController *)fromVC
                                                  toViewController:(UIViewController *)toVC
{
    NSLog(@"from VC class %@", [fromVC class]);
    if ([fromVC isKindOfClass:[ControllerYouJustPopped class]])
    {
        NSLog(@"Returning from popped controller");

    }

    return nil;
}
like image 1
Vladimir Stazhilov Avatar answered Nov 16 '22 14:11

Vladimir Stazhilov