【发布时间】:2011-12-18 10:55:36
【问题描述】:
我想在导航控制器中单击后退按钮时保存 DB。
所以我会在方法中插入代码。
在导航控制器中单击后退按钮时调用什么方法?
【问题讨论】:
-
使用标志变量。如果 DB 未更新,则在 viewWillDisappear 方法中更新 DB。这应该有效。
标签: ios xcode controller navigation back-button
我想在导航控制器中单击后退按钮时保存 DB。
所以我会在方法中插入代码。
在导航控制器中单击后退按钮时调用什么方法?
【问题讨论】:
标签: ios xcode controller navigation back-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;
}
【讨论】: