viewDidLoad 时使用 NSUserDefaults 加载存储的注释的字幕
基本上,我尝试做的是将副标题(街道地址)保存到注释中。当应用程序终止并再次启动时,我希望此存储的字幕显示在注释的标注中。我做错了什么?我只是无法让它工作...
storeLocation.m
- (void)setCoordinate:(CLLocationCoordinate2D)coor {
............
NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
[userDef setValue:subtitle forKey:@"SavedAddress"];
[userDef synchronize];
NSLog(@"Stored subtitle");
}
mainViewController.m
-(void)viewDidLoad {
NSString *savedAddress = [[NSUserDefaults standardUserDefaults] objectForKey:@"SavedAddress"];
if (savedAddress) {
}
}
非常感谢对此的一些帮助... 提前致谢!
Basically, what I try to do is to save a subtitle(the street address) to an annotation. When the application terminates and starts again I want this stored subtitle to show up in the callout of the annotation. What am I doing wrong? I just can't get it to work...
storeLocation.m
- (void)setCoordinate:(CLLocationCoordinate2D)coor {
............
NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
[userDef setValue:subtitle forKey:@"SavedAddress"];
[userDef synchronize];
NSLog(@"Stored subtitle");
}
mainViewController.m
-(void)viewDidLoad {
NSString *savedAddress = [[NSUserDefaults standardUserDefaults] objectForKey:@"SavedAddress"];
if (savedAddress) {
}
}
Would really appreciate some help with this one... Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用
srtingForKey:
而不是objectForKey:
try
srtingForKey:
instead ofobjectForKey:
我用 if 语句解决了这个问题,所以
:
I solved it with an if-statement in the
So that: