0

I have a MapAnnotation that I added custom fields to so when the user clicks on the pin I perform a segue to another view controller where I try to set labels to these custom fields. The problem is I'm not getting the values in the veiwcontroller so it's not persisting. I am new to iOS dev so I am probably missing something.

Here is where I set the MapAnnotation

 NSArray *json = [NSJSONSerialization JSONObjectWithData:data
                                                options:kNilOptions
                                                  error:&error];

for (MapAnnotation *record in json) {

  //  NSLog(@"%lu", (unsigned long)json.count);

    MapAnnotation *temp = [[MapAnnotation alloc]init];
    [temp setTitle:[record valueForKey:@"city"]];
    [temp setSubtitle:[record valueForKey:@"region"]];
    [temp setHeatmap:[record valueForKey:@"iframe_heatmap_url"]];
    [temp setPercentViewed:[record valueForKey:@"percent_viewed"]];
    [temp setOrg:[record valueForKey:@"org"]];
    [temp setEmbedURL:[record valueForKey:@"embed_url"]];
    [temp setCoordinate:CLLocationCoordinate2DMake([[record valueForKey:@"lat"]floatValue], [[record valueForKey:@"lon"]floatValue])];
    [retval addObject:temp];

Is there something I need to do to persist this to the other view controller? I am simply importing the MapAnnotation class into the view controler and setting the labels text to the fields in my custom class:

Custom Annotation Class

@interface MapAnnotation : NSObject<MKAnnotation>

@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@property (nonatomic, copy) NSString *org;
@property (nonatomic, copy) NSString *percentViewed;
@property (nonatomic, copy) NSString *heatmap;
@property (nonatomic, copy) NSString *embedURL;

@end
Sam Cromer
  • 687
  • 3
  • 12
  • 31
  • Show the code that handles the pin tap and performs the segue. Also see http://stackoverflow.com/questions/14805954/mkannotationview-push-to-view-controller-when-detaildesclosure-button-is-clicked (might be what you're looking for). Note that in performSegueWithIdentifier, the sender is set to `view` (ie. the MKAnnotationView). –  Feb 15 '14 at 13:31
  • - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view { NSLog(@"annotation selected"); [self performSegueWithIdentifier:@"MoreDetails" sender:self]; } – Sam Cromer Feb 18 '14 at 20:42
  • Instead of `sender:self`, use `sender:view`. See how the linked answer calls `performSegueWithIdentifier`. –  Feb 18 '14 at 21:08

0 Answers0