【问题标题】:Which method is called when back button clicked in navigation controller?在导航控制器中单击后退按钮时调用哪个方法?
【发布时间】:2011-12-18 10:55:36
【问题描述】:

我想在导航控制器中单击后退按钮时保存 DB。

所以我会在方法中插入代码。

在导航控制器中单击后退按钮时调用什么方法?

【问题讨论】:

  • 使用标志变量。如果 DB 未更新,则在 viewWillDisappear 方法中更新 DB。这应该有效。

标签: ios xcode controller navigation back-button


【解决方案1】:

按你说的做,看UINavigationControllerDelegate协议,即方法:

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

当 viewController 参数不再是您的视图控制器时,您应该保存。

但是,在 viewWillDisappear: 上这样做可能是一个更好(也更简单)的想法。

【讨论】:

    【解决方案2】:

    也许它不适合使用,但这对我有用。不要忘记设置 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;
    }
    

    【讨论】:

      猜你喜欢
      • 2012-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-29
      • 1970-01-01
      • 2011-07-10
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多