Note that there are some explanatory texts on larger screens.

plurals
  1. POMapKit update annotation image
    text
    copied!<p>I'm having a problem finding out the way to update a custom <code>MKAnnotationView</code> image after a asynchronous request completes with information about the status of the annotation. So far, I have this:</p> <pre class="lang-c prettyprint-override"><code>- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation { static NSString *identifier = @"EstacionEB"; if ([annotation isKindOfClass:[EstacionEB class]]) { EstacionEB *location = (EstacionEB *) annotation; CustomPin *annotationView = (CustomPin *) [_mapita dequeueReusableAnnotationViewWithIdentifier:identifier]; if (annotationView == nil) { annotationView = [[CustomPin alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; } else { annotationView.annotation = annotation; } UIImage * image = [UIImage imageNamed:[NSString stringWithFormat:@"%@.png", [location elStatus]]]; annotationView.enabled = YES; annotationView.canShowCallout = YES; annotationView.image = image; NSDictionary *temp = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:annotationView, location, nil] forKeys:[NSArray arrayWithObjects:@"view", @"annotation", nil] ]; //This array is synthesized and inited in my controller's viewDidLoad [self.markers setObject:temp forKey:location.eid]; return annotationView; } return nil; } </code></pre> <p>A little after, I do a request and with the results, an NSDictionary, I'm trying to do the following, which returns null to both elements:</p> <pre class="lang-c prettyprint-override"><code>- (void)updateStation:(NSString *)eid withDetails:(NSDictionary *)details { NSInteger free = [details objectForKey:@"free"]; NSInteger parkings = [details objectForKey:@"parkings"]; NSDictionary *storedStations = [self.markers objectForKey:eid]; CustomPin *pin = [storedStations objectForKey:@"view"]; //nil EstacionEB *station = [referencia objectForKey:@"annotation"]; //nil as well [station setSubtitle:free]; NSString *status; if( free==0 ){ status = @"empty"; } else if( (free.intValue&gt;0) &amp;&amp; (parkings.intValue&lt;=3) ){ status = @"warning"; } else { status = @"available"; } UIImage * image = [UIImage imageNamed:[NSString imageWithFormat:@"%@.png", status]]; pin.image = image; } </code></pre> <p>This brings up no errors (assuming I pasted and traduced everything correctly), but the NSMutableDictionary that should contain both my custom MKAnnotationView and the MKAnnotation, but even when I log them all before the request completes and it appears correctly, when the request completes its as if both the MKAnnotationView and MKAnnotation are just not what I expected, and thus, I can't modify the annotations to change the image or update the annotation view.</p> <p>Any ideas would be appreciated!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload