开发者

The Proper Way to Store and Access Objects in Memory on the iPhone

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 o开发者_Python百科r is there a better way?


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:

  1. A singleton
  2. In the application delegate (somewhat frowned upon)
  3. As an object passed amongst the view controllers in your navigation hierarchy (makes sense in a document or file based application)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜