Storing and loading a subtitle of an annotation with NSUserDefualts

Posted by Krismutt on Stack Overflow See other posts from Stack Overflow or by Krismutt
Published on 2011-01-01T16:34:34Z Indexed on 2011/01/01 16:53 UTC
Read the original article Hit count: 229

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!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about nsuserdefaults