在导航控制器中单击后退按钮时会调用哪个方法?

发布于 2024-12-12 22:37:39 字数 82 浏览 5 评论 0原文

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

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

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

紫轩蝶泪 2024-12-19 22:37:40

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

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;
}
泡沫很甜 2024-12-19 22:37:39

要执行您要求的操作,请查看 UINavigationControllerDelegate 协议,即方法:

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

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文