Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying MKAnnotation callout automatically

Why doesn't this work?

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
    if (TRACE_LOG) NSLog(@"%s", __FUNCTION__);

    [mapView selectAnnotation:[views lastObject] animated:YES];

    return;
}

Thanks, Z@K!

like image 211
Zak Avatar asked Jan 21 '23 14:01

Zak


1 Answers

Because you must select annotation object, not the view that corresponds to it.

I'm 100% not sure, but I think the following should work:

MKAnnotationView* annotationView = (MKAnnotationView*)[views lastObject];
[mapView selectAnnotation:annotationView.annotation animated:YES];

If you store your annotations somewhere it might be better to get annotation object you need directly from that storage. Note that all these methods have affect only if you try to select annotation that is currently visible on screen.

like image 171
Vladimir Avatar answered Feb 05 '23 00:02

Vladimir