ios - viewWillDisappear, viewWillUnload viewDidUnload 从未调用

标签 ios uiview uiviewcontroller

我的 Root View Controller 上的方法 viewWillDisappear, viewWillUnload viewDidUnload永远不会被调用(每个都有日志语句)。

似乎这已经出现在这里,但答案并不完全清楚。这似乎暗示需要将 viewController View 嵌入到 UINavigationController 中。这似乎很奇怪,而且我在其他任何地方都没有提到过。

viewWillDisappear and viewDidDisappear never get called

如果是这种情况,我还能在哪里进行一些清理并确保我的 UIDocument 更改得到保存?

编辑:猜猜我误解了@ root viewController 事件的工作方式(它是独特的状态等)。将研究 AppDelegate 方法。只是想确保我的 UIDocument 内容得到保存,并且我的核心音频内容被正确关闭。

关闭:
最终得到了 AppDelegate 发布的通知。执行一次后似乎效果很好+简单的东西。

//来自 appDelegate

- (void)applicationDidEnterBackground:(UIApplication *)application
{

[[NSNotificationCenter defaultCenter] postNotificationName: @"handleCleanup" 
                                                    object: nil 
                                                  userInfo: nil];
}

和我的 VC 注册通知:
    [[NSNotificationCenter defaultCenter] addObserver: self 
                                         selector: @selector(saveAndCleanup) 
                                             name: @"handleCleanup" 
                                           object: nil];

最佳答案

如果它是你的 Root View ,而你永远不会改变它——那么它就不会消失。虽然,当您将应用程序置于后台时,可能会调用 viewWillDisapear - 我不记得了。

只有当您收到内存警告时,您的 View Controller 才会被卸载,但如果它在屏幕上 - 它不会被卸载。

View 将消失:

This method is called in response to a view being removed from a view hierarchy. This method is called before the view is actually removed and before any animations are configured.



viewDidUnload:

When a low-memory condition occurs and the current view controller’s views are not needed, the system may opt to remove those views from memory. This method is called after the view controller’s view has been released and is your chance to perform any final cleanup. If your view controller stores separate references to the view or its subviews, you should use this method to release those references. You can also use this method to remove references to any objects that you created to support the view but that are no longer needed now that the view is gone. You should not use this method to release user data or any other information that cannot be easily recreated.

关于ios - viewWillDisappear, viewWillUnload viewDidUnload 从未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9977726/

相关文章:

iphone - ios 如何在 drawrect 方法中在图像上画一条线

ios - 灰度 UIView。 View 未重绘

ios - 如何使用 Swift 检测 iOS 应用何时出现在前台?

ios - 为 iOS 中的每个 View Controller 动态添加自定义 View

ios - 在 iPhone SDK 后台调用电话

ios - ipad 如何在一个 View 上以编程方式创建多个表

iphone - 从 iOS 发送的 PDF 附件在 Outlook 邮件客户端中未正确显示

ios - 是否可以保存 NSManagedObjectModel?

ios - 扩展 UIView 而不调整大小或重绘

ios - shouldAutorotate 未被调用