我遇到了如下所示的代码。在下面的代码中,我只能保存一个注释,但是我有一组注释,我无法用单个 NSUserDefaults 保存它们
To save:
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
[ud setDouble:location.latitude forKey:@"savedCoordinate-latitude"];
[ud setDouble:location.longitude forKey:@"savedCoordinate-longitude"];
[ud setBool:YES forKey:@"savedCoordinate-exists"];
[ud synchronize];
编辑:
-(void)viewDidLoad
NSUserDefaults *ud=[NSUserDefaults standardUserDefaults];
if([ud boolForKey:@"save-exist"])
{ NSMutableArray *udAnnotations=[[NSMutableArray alloc]initWithArray:
[ud objectForKey:@"annotationsArray"]];
NSLog(@"%d",[udAnnotations count]);
}
else{
[self addAnno];
}
-(void)addAnno
{
[mapView addAnnotations:annotationArray];
NSUserDefaults *ud=[NSUserDefaults standardUserDefaults];
[ud setObject:annotationArray forKey:@"annotationsArray"];
[ud setBool:YES forKey:@"save-exist"];
[ud synchronize];
}