开发者

How to share data globally among multiple view controllers

can anybody help me out please...

i have a huge object in a model. i made it as a single ton class and returning the object wn other calls.but the object is very big thats y the app is crasing. with out returning how to share the data globally and when to alloc the object and where to dealloc the ob开发者_如何学Cject. i dont need all the data in object in a viewcontroller ..i need specific data to a view controller from that object...

Thanks.


You can store a pointer to it in your app delegate and retrieve it using

BlahAppDelegate* delegate = [[UIApplication sharedApplication] delegate];
id bigObject = delegate.bigObject;

Since the app delegate will outlive the view controllers, you shouldn't have to worry about retain and release for it.

A singleton class should work similarly, as long as the singleton instance method (that retrieves the one created instance) calls retain on the instance when before it returns it. When the view is dealloc-ed, make sure you call release on the instance.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜