简体   繁体   中英

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 NSMutableArray 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM