Im thinking a program that has made up by navigation bar with multiple views. so basically I want to access data(& storing data) to one same object class through the whole stack of navigation. for ex开发者_开发技巧ample, 1. choose a picture from firstview, store the picture to the object class. 2. change to other view and access the picture from the smae object class. 3. as a next step on the other view, also can access and store the data to this object class.
what I want to know now is how to maintain and access the same file from the all different levels of the program. please give me some tips!
You can make the UIImageView
or other NSObject
a property of the rootViewController
, and then access it by:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
UIViewController *theRootViewController = appDelegate.rootViewController;
NSObject *myObject = theRootViewController.myobject;
However, if what you're passing is an NSArray
or BOOL
or float
or int
, then you can also consider using NSUserDefaults
to save and load from anywhere within the app.
精彩评论