I have a tab bar item which shows users favorites in a tableview. I have another tab bar item which shows a view and allows the user to add a favorite.
Update
this array of favourites gets read from NSUserDefaults in the viewDidLoadMethod of the class which creates and add a favorite.
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSArray *prefs = [def arrayForKey:@"addedQuotes"];
userAddedQuotes = [[NSMutableArray alloc] initWithArray:prefs];
then this code executes when the user actually adds a favorite
if([text1.text length] && [text2.text length])
{
NSString *temp = [NSString stringWithFormat:@"%@^%@",
text1.text, text2.text];
[userAdded addObject:temp];
NSUserDefaults *myDefault = [NSUserDefaults standardUserDefaults];
[myDefault setObject:userAdded forKey:@"addedFavorites"];
In the tableview class which loads this array from NSUserDefaults to display the values I use the following in the viewWillAppear method.
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
NSArray *prefs = [def arrayForKey:@"addedFavorites"];
favorites = [[NSMutableArray alloc] initWithArray:prefs];
At the moment if I add a favorite and then go to the show favorites tab view, it doesnt load the newly added items. only when I exit(press the home button) and start the application again.
How can I get the view to read from the userdefaults again when the tab bar item is selected and the view is shown?
Regards