Storing and loading a subtitle of an annotation with NSUserDefualts
- by Krismutt
Happy new year everybody!
Basically, what I try to do is to save a subtitle to an annotation when the application terminates. When the application starts again I want this stored subtitle to show up in the callout of the annotation again. What am I doing wrong? I just can't get it to work...
storeLocation.m
- (void)setCoordinate:(CLLocationCoordinate2D)coor {
MKReverseGeocoder *geocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:coor] autorelease];
geocoder.delegate = self;
coordinate = coor;
[geocoder start];
NSUserDefaults *userDef = [NSUserDefaults standardUserDefaults];
[userDef setValue:subtitle forKey:@"SavedAddress"];
[userDef synchronize];
NSLog(@"Sparade adress");
}
mainViewController.m
-(void)viewDidLoad {
NSString *savedAddress = [[NSUserDefaults standardUserDefaults] objectForKey:@"SavedAddress"];
if (savedAddress) {
// what code should I add here
// so that the subtitle shows up
// when the application launches?
}
}
Would really appreciate some help with this one...
Thanks in advance!