Search code examples
iphoneios4nsuserdefaultsmkannotationmkannotationview

Loading a stored annotation's subtitle with NSUserDefaults when viewDidLoad


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!


Solution

  • try srtingForKey: instead of objectForKey:

    NSString *savedAddress = [[NSUserDefaults standardUserDefaults] stringForKey:@"SavedAddress"];