i have an app that generates different questions. i have a tab bar at the bottom that lets users view "recents" and also "favorites." i'm using nsuserdefaults to save the array of favorites/recents into a table.
for some reason i can never add to favorites/recents on the initial installs of the appilcation. it only works once I have opened my recents/favorites and then exit and re-launch the program. b/c of that i think it may be related to something within my "viewWillAppear" but i'm not totally sure.
Code:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate];
self.myFavorites = [NSMutableArray arrayWithArray:appDelegate.favoriteQuestions1];
self.myFavorites2 = [NSMutableArray arrayWithArray:appDelegate.favoriteQuestions2];
self.myCategories = [NSMutableArray arrayWithArray:appDelegate.favoriteTypes];
self.myVerses = [NSMutableArray arrayWithArray:appDelegate.favoriteVerses];
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// saving the array
[prefs setObject:myFavorites forKey:@"favorites1"];
[prefs setObject:myFavorites2 forKey:@"favorites2"];
[prefs setObject:myCategories forKey:@"favoriteTypes"];
[prefs setObject:myVerses forKey:@"favoriteVerses"];
[prefs synchronize];
[self.tableView reloadData];
}
does this look like it could be the cause of my problem? if not, where should I look?