在导航控制器中点击后退button时会调用哪种方法?
我想在导航控制器中点击后退button时保存数据库。
所以我会在方法中插入代码。
在导航控制器中点击后退button时会调用什么方法?
要做你所问的,看看UINavigationControllerDelegate
协议,即方法:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
当viewController参数不再是你的视图控制器,那么你应该保存。
然而,这样做的观点将会viewWillDisappear:
可能是一个更好的(也更简单)的想法。
也许这是不适当的使用,但是这对我有效。 不要忘记设置UINavaigationController委托。
- (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; }