OGeek|极客世界-中国程序员成长平台

标题: 用于 uinavigationcontroller 的 iOS 开源智能 Controller 推送/弹出库? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:30
标题: 用于 uinavigationcontroller 的 iOS 开源智能 Controller 推送/弹出库?

我有一个应用程序,用户可以在其中无限深入地推送 View (推送到导航堆栈)。在某些时候,会出现内存警告。我想从导航 Controller 中删除 View Controller 并释放它们。如果用户回到那些 View Controller ,我想重新创建 View Controller 并将它们推回堆栈中的正确位置。

这是思考这个问题的正确方法吗?

是否有一个开源项目可以做到这一点?这似乎不是一个不常见的问题,我宁愿不重新发明轮子。



Best Answer-推荐答案


曾几何时,您需要确保对 viewDidLoadviewDidUnload 的调用正确匹配,以便以这种方式处理内存警告。从 iOS 6 开始,这不再需要。

正如 viewDidUnload 的文档中所说:

In iOS 5 and earlier, when a low-memory condition occurred and the current view controller’s views were not needed, the system could opt to call this method after the view controller’s view had been released. This method was your chance to perform any final cleanup. If your view controller stored separate references to the view or its subviews, you could use this method to release those references. You could 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 would not use this method to release user data or any other information that cannot be easily recreated.

In iOS 6 and later, clearing references to views and other objects in your view controller is unnecessary.

如果您手动将大型对象保存在内存中,例如图像或视频数据,那么您可以覆盖 didReceiveMemoryWarning 以在必要时释放这些对象。

关于用于 uinavigationcontroller 的 iOS 开源智能 Controller 推送/弹出库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24373489/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4