如下所示的代码,它不会给我我的可变数组。我的可变数组中有 3 个注释,但是一旦我关闭我的应用程序并再次打开它,它就会显示 0 个对象。我不知道为什么我在取回数组时会得到 O 个对象!任何想法?
-(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];
}