我是否必须保留放入 UIKit 应用程序视图中的所有值的副本?
我有一个视图控制器,其中的视图是从 NIB 加载的。据我了解,控制器可以随时从内存中卸载视图。例如,假设我的应用程序进入后台。
如果我有值,例如文本字段中的文本,则卸载视图时这些值将丢失。或者我可能想在加载视图之前设置这些值,在这种情况下,我的插座尚未设置,而且我还无法执行此操作。
因此,我是否需要保留用户界面中所有值的影子副本,以便在视图卸载然后再次加载时可以在 viewDidLoad: 中重新设置它们?
或者我做事的方式不对?
I have a view controller with a view loaded from a NIB. As I understand it, the view can be unloaded from memory at any time by by controller. Say my app goes into the background, for example.
If I have values, such as text in a text field, those values will be lost when the view is unloaded. Or I might want to set those values before the view is loaded, in which case my outlets are not set and I am not able to do it yet.
Therefore, do I need to keep a shadow copy of all values in my user interface, so that I can re-set them in viewDidLoad: if the view gets unloaded and then loaded again?
Or am I doing things the wrong way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果应用程序进入后台,请实现保存和恢复应用程序的方法。 UIApplication 将让您知道焦点何时在以下 UIApplicationDelegate 方法中发生变化:
有关更多详细信息,请参阅帮助。
忘记了内存警告...
解决方案取决于具体情况。根据我的经验,当您的可见视图被删除以清除一些内存时,您不想实现恢复机制,而是测试内存泄漏,观察内存分配,优化内存管理或重新考虑设计。
In case of app going to background, implement methods to save and restore app. UIApplication will let you know when focus is going to and has changed in following UIApplicationDelegate methods:
See help for more details.
Forgot about memory warnings...
Solutions depend from case to case. In my experience, when it comes to the point when your visible view is removed to clear some memory, you don't want to implement recovery mechanism but test for memory leaks, observe memory allocations, optimize memory management or rethink design.