I am trying to save a NSMutableArray
to NSUserDefaults
then reload it and use it to populate the button labels. Can someone please take a look and tell me what i am doing wrong here?
When I am loading the file to new array it appears empty. All of the buttons I am trying to set the titles to are in ibCollectionOutlet called buttons
-(void)save {
[[NSUserDefaults standardUserDefaults] setObject:self.pressCountArray forKey:@"savedFile"];
[[NSUserDefaults standardUserDefaults] synchronize];
}
-(void)load{
NSMutableArray *countArray = [[[NSUserDefaults standardUserDefaults] arrayForKey:@"savedFile"] mutableCopy];
for (NSInteger i = 0; i < [self.pressCountArray count]; i++){
self.pressCountArray[i] = countArray[i];
}
for (NSInteger i = 0; i < [self.buttons count]; i++){
UIButton *btn = self.buttons[i];
int curCnt = [[self.pressCountArray objectAtIndex:i] integerValue];
[btn setTitle:[NSString stringWithFormat:@"%i",curCnt] forState:UIControlStateNormal];
}
}