views:

134

answers:

1

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!

A: 

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.

Vladimir
Would you mind throwing a code example in there too?
Zak
Thanks, that was great help. This is what I ended up having to do.`if ( [[[views lastObject] annotation] isKindOfClass:[CustomAnnotation class]] ) {``[mapView selectAnnotation:(CustomAnnotation *)[[views lastObject] annotation] animated:YES];``}`
Zak