未在viewWillDisappear中设置isBeingDismissed: [英] isBeingDismissed not set in viewWillDisappear:

查看:544
本文介绍了未在viewWillDisappear中设置isBeingDismissed:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的viewWillDisappear:中有一些代码需要清理,我只想在视图移回到父视图控制器时使用.

I have some code to clean up in my viewWillDisappear:, which I only want to use when the view is moving back to the parent view controller.

- (void)viewWillDisappear:(BOOL)animated
{
    if ([self isMovingFromParentViewController] || [self isBeingDismissed]) {
        NSLog(@"isMovingFromParentViewController or isBeingDismissed");
        // clean up
    }
    [super viewWillDisappear:animated];
}

视图可以通过两种方式呈现:可以由导航控制器推送,也可以作为模态视图控制器呈现(来自同一导航控制器).如果将其按下然后弹出(按后退"按钮),则将运行我的清理代码.如果它以模态视图控制器的形式出现,然后将其关闭,则该代码将不会运行.

The view can be presented in two ways: it can be pushed by a navigation controller, or presented as a modal view controller (from the same navigation controller). If it's pushed, then popped (pressing the back button), my clean-up code runs. If it it presented as a modal view controller, then dismissed, the code doesn't run.

我这样解雇:

[rootViewController dismissModalViewControllerAnimated:YES];

我的问题是:为什么我关闭视图控制器时没有设置isBeingDismissed?

My question is: why isn't isBeingDismissed set when I dismiss my view controller?

推荐答案

您的问题是如何取消模态视图. rootViewController是如何定义的?

Your issue is how you are dismissing your modal view. How is rootViewController being defined?

当我呼叫[self dismissModalViewControllerAnimated:YES]时,[self isBeingDismissed]的计算结果为true.

When I call [self dismissModalViewControllerAnimated:YES] then [self isBeingDismissed] evaluates to true.

当我调用[parentViewController dismissModalViewControllerAnimated:YES]时,[self isBeingDismissed]的计算结果为true,其中parentViewController是呈现模式视图的UIViewController(注意:不是UINavigationController).

When I call [parentViewController dismissModalViewControllerAnimated:YES] then [self isBeingDismissed] evaluates to true, whereby parentViewController is the UIViewController that presented the modal view (note: not a UINavigationController).

这篇关于未在viewWillDisappear中设置isBeingDismissed:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆