在 iPhone 内存中存储和访问对象的正确方法
我是 iOS 编程新手,我想弄清楚在内存中存储对象的广泛接受的“正确”方式是什么?
在我的程序中,我在导航控制器中有几个视图控制器,然后在最下面的视图上有一个模态视图控制器。
我有一类对象,我将其存档在文件中,并在需要更改对象成员变量时取消存档。我需要能够访问和更改我从所有视图控制器存档的这些对象。
通过取消归档然后归档每个视图控制器中的数据是正确的方法还是有更好的方法?
I'm new to programming in iOS and I'm trying to figure out what the widely accepted "proper" way to store objects in memory is?
In my program I have a couple view controllers in a navigation controller and then on the lowermost view I have a modal view controller.
I have a class of object that I archive in a file and unarchive when I need to change the objects member variables. I need to be able to access and change these objects that I have archived from all of my view controllers.
Is the proper way to do this by unarchiving and then archiving the data in each view controller or is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
多个视图控制器(即从 UIViewController 派生的类)确实令人不悦。视图控制器应该控制屏幕(或者在极少数情况下,例如 iPad 拆分视图,可以有两个)。如果您需要多个类来管理不同的子视图,那很好,只是不要继承自 UIViewController 。
根据您的应用程序,您可以将数据保存在:
Multiple view controllers (that is classes deriving from UIViewController) is really frowned upon. A view controller should control the screen (or in rare cases such as the iPad split view, there can be two). If you need multiple classes to manage different subviews, thats fine, just don't inherit from UIViewController.
Depending on your application, you can keep your data in: