Hi there all,
ive been stuck with this problem for a couple of days now and cant seem to get anywhere.
Basically I want to copy dictionaries between views.
In one view I have a table with some data.Its using a plist, with an array of dictionaries.
In the other view, once again a table but I want to be able to fill this table with a user selection of dictionaries from the first view.
This is how i have set it up:
I have 3 viewControllers:
1stTableViewController--------main table view with all data
2ndTableViewController-------user selected table view
DetailViewController-----------show the details of selected row
So in the detailview I have made a button to "watch" a entry.
What I mean is like in the ebay app, you can select items to put in your watch list.
Inside my button pressed method i have done this:
Code:
- (IBAction)watchButtonPressed:(id)sender {UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Watch?" message:@"You wanna watch?" delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];[alert show];
// Retrieve Selected rows data from 1stVC
NSString *publisher = [book objectForKey:PUB_KEY];
NSString *name = [book objectForKey: NAME_KEY];
NSString *description = [book objectForKey: INFO_KEY];
NSString *errorDesc;
//Creating a delegate so I can access the mutable dictionary data
myAppDelegate *delegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
NSDictionary *plistDict = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects: name, publisher, description, nil] forKeys:[NSArray arrayWithObjects:@"Name", @"Publisher", @"Description", nil]];
NSData *plistData = [NSPropertyListSerialization dataFromPropertyList:plistDict format:NSPropertyListXMLFormat_v1_0 errorDescription:&errorDesc];
//Adding plistDict to data Dictionary
[delegate.data addObject:plistData];
now that finds the data corresponding to the selected row.Creates a dict with that data and then adds it to an array in my appDelegate called "data".
well, at least i think it should.
In my 2ndTable VC i have this :
Code:
myAppDelegate *delegate = (myAppDelegate *)[[UIApplication sharedApplication] delegate];
myBooks = delegate.data;
myBooks is an array which will feed the table view.
Now when I try run this in the simulator it doesnt pass the data.
Can anyone help me with this?
Is my method of passing data thru the appDelegate right?
Can I do this?