tags:

views:

31

answers:

3

I have a plist (dictionary type) populating text views and labels on one view. I would like to have an info UIButton on this first view that links to a separate view and displays some data from the same plist.

it has to be data from the same record in the plist though.

I have everything working, but I'm stuck at being able to pass that data to the second view.

any hints/help is greatly appreciated,

thanks,

A: 

You could open the same plist in the next view and read the data in the same way:

NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Info.plist"];
NSDictionary *plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];

You could make a Singleton accessor class for your dictionary and have both views request an instance of it to gain access to the same data.

Or if you create your views programmatically, you could just create a setter in your new view controller and pass a reference of your dictionary from the original view controller.

Winder
would the record in the plist be the same? if a user chose a certain record in the plist on view 1, then clicked the info UIButton for view 2, would the records still match? thanks again
hanumanDev
+1  A: 

Or you could make a property in the info view.

@property(nonatomic, retain)NSDictionary *myDic;

And when you create the Info view, pass your dictionary with the data to the second view, which then displays the data. ;-)

Sandro Meier
that makes sense. I've been searching through Apple's sample code but couldn't find an example of this yet.
hanumanDev
A: 

You could just Create a NSDictionary in the .h file of the second view and then when you are moving to the next view set the dict you want to pass as that dictionary.

SecondView* view = [SecondView .......
view.passedDictionary = currentDict;
//then push the new view onto the screen

In the .h file of the second view

NSDictionary* passedDictionary;
@property(nonatomic, retain) NSdictionary* passedDictionary;
octermircty