Which method is called when the back button is pressed in the navigation controller?

I want to save the database when the back button is pressed in the navigation controller.

so I would enter the code in the method.

Which method is called when the back button is pressed in the navigation controller?

+10
ios xcode back-button navigation controller
Oct 31 2018-11-11T00:
source share
2 answers

To do what you requested, 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, you must save it.

However, executing this function viewWillDisappear: might be a better (and much simpler) idea.

+8
Oct 31 '11 at 2:00
source share

It may not work, but it worked for me. Remember to specify the 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; } 
+1
Jun 27 '14 at 14:30
source share



All Articles