开发者

Passing objects from AppDelegate.m to View Controller

Hi I have an iphone application in which I am fetching & parsing data in in applicationDidFinishLaunching. Now I want to transfer this fetched data which is in one NSMut开发者_如何学CableArray to my first view controller to display it there.

Whats the best way of doing this...


You can past it through the init like initWithDataArray: , I think that is good enough.

Another solution, which imo is worse, is parsing the AppDelegate to the ViewController and then you can call : appDelegate.dataArray but it will leak out too much information


Application Delegate is what i prefer in this case.

//Declare NSMutableArray object in AppDelegate.h ,Now property & synthesize it

//Store your data in NSMutableArray object

//Create ApplicationDelegate object any your View Controller Class

yourApplicationAppDelegate *appDelegate;

appDelegate = (yourApplicationAppDelegate *)[[UIApplication sharedApplication] delegate];

Now you can access NSMutableArray object through appDelegate any where in your application

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜