调用popToRootViewControllerAnimated时未调用viewWillDisappear [英] viewWillDisappear not called when calling popToRootViewControllerAnimated

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

问题描述

我在旧版应用程序上工作,发现我的view[Will/Did]Disappear方法并非总是能正确触发.

I work on a legacy application, and have found out, that my view[Will/Did]Disappear methods are not always fired properly.

情况是,我在AppDelegate中将一个(自定义)UIViewController设置为rootViewController.这个rootViewController有一个UINavigationController,上面有两个视图控制器.当用户按下主页按钮时,该用户将注销.当他稍后返回应用程序时,该应用程序调用[UINavigationController popToRootViewControllerAnimated:YES],然后显示模式UIViewController进行登录.

The case is, I have a (custom) UIViewController set as rootViewController in AppDelegate. This rootViewController has a UINavigationController, which has two view controllers pushed on it. When the user presses the home button, the user is logged out. When he later returns to the app, the application calls [UINavigationController popToRootViewControllerAnimated:YES] and then displays a modal UIViewController for logging in.

问题是:当我正常地在UINavigationController上推入/弹出时,我的viewWillDisappear方法会被正确调用.但是当我使用popToRootViewControllerAnimated:方法时,在弹出的所有viewController上都不会调用viewWillDisappear.

The problem is: When I push/pop on the UINavigationController normally, my viewWillDisappear method is called properly. But when I use the popToRootViewControllerAnimated: method, viewWillDisappear is not called on any of the viewControllers that are popped off.

在Internet上搜索仅给出两个可能的原因:

Searching on the internet has only given two possible reasons:

这些建议在我的应用程序中都不存在.而且我不知道在哪里看.有人对应用程序做错了什么建议吗?

None of these suggestions are the case in my app. And I have no idea where to look. Anybody has a suggestion to what has been done wrong in the app?

推荐答案

该视图可能不在屏幕上.必须在屏幕上(可见)调用viewWillDisappear:方法.如果它是从后台回来的,则看不到.

The view probably wasn't onscreen. It has to be onscreen (visible) for the viewWillDisappear: method to be called. If it's coming back from the background, it wasn't visible.

您可以尝试使用willMoveToParentViewController:,当视图控制器从其父级中移除时会调用它.

You could try using willMoveToParentViewController: which is called when the view controller is removed from its parent.

这篇关于调用popToRootViewControllerAnimated时未调用viewWillDisappear的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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