gpt4 book ai didi

ios - viewWillDisappear, viewWillUnload viewDidUnload 从未调用

转载 作者:行者123 更新时间:2023-12-01 19:21:52 25 4
gpt4 key购买 nike

我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com