我希望在退出应用程序时存储我的注释,并在启动应用程序时再次弹出....我怎样才能实现这一点?有什么想法吗?
-(IBAction)storeLocation:(id)sender{
SparaPosition *position=[[SparaPosition alloc] initWithCoordinate:location];
[mapView addAnnotation:position];
savedPosition = location;
请...需要一些帮助!
谢谢!
答案 0 :(得分:2)
如果您只想保存一个注释的坐标,最简单的方法是使用NSUserDefaults。
保存:
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];
加载(例如在viewDidLoad中):
NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
if ([ud boolForKey:@"savedCoordinate-exists"])
{
CLLocationCoordinate2D savedCoordinate;
savedCoordinate.latitude = [ud doubleForKey:@"savedCoordinate-latitude"];
savedCoordinate.longitude = [ud doubleForKey:@"savedCoordinate-longitude"];
//create annotation object using savedCoordinate and add to map view...
}