Hey guys, a mutable array in my app is not accepting objects from another class.
Basically I add a NSMutableDictionary in one view to an NSMutableDictionary assigned in my app Delegate and pass the data to another view, in which I want to populate my table view.
So the variable in my app delegate holds the dictionary selected in the first view.Ive got his verified with NSLog.
In my table view (second view) the app delegate has data.
Then my code to add dictionary from app delegate to NSMutableArray in table view and NSMutableArray = null. . . .
Can someone look at my code and point me in the right direction???
Here is where I set the Dictionary in the first view:
Code:
NSString *publisher = [book objectForKey:PUB_KEY];
NSString *name = [book objectForKey: NAME_KEY];
NSString *description = [book objectForKey: INFO_KEY];
//Creating a delegate so I can access the mutable dictionary data
TESTAppDelegate *delegate = (TESTAppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableDictionary *plistDict = [NSMutableDictionary dictionaryWithObjects:[NSArray arrayWithObjects: name, publisher, description, nil] forKeys:[NSArray arrayWithObjects:@"Name", @"Publisher", @"Description", nil]];
//Adding plistDict to data Dictionary
delegate.data = plistDict;
NSLog(@"delegate.data In First View: %@",delegate.data);
So that adds the dictionary created into delegate.data---the NSMutableDictionary in app Delegate.
Now my table view:
Code:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
TESTAppDelegate *delegate = (TESTAppDelegate *)[[UIApplication sharedApplication] delegate];
[tempArray init];
[tempArray addObject:delegate.data ];
NSLog(@"tempARRAY in tableview: %@",tempArray);
NSLog(@"delegate.data: %@",delegate.data);
self.myBooks = tempArray;
[self.tableView reloadData];
}
So here when the view loads every time, I init a array: tempArray, and add delegate.data to it.Then "myBooks" Mutable Array = tempArray.Which I then use to fill my tableview , cell, ect with.
now the logs say that delegate.data in the tableview IS the saved dictionary assigned in first view.But tempArray = null....
Any help or push in the right direction?