没有在iOS5中selectMKAnnotation

我的应用程序在地图上放置了一个图钉,然后select使用的animation,这样用户就有一个视觉线索,可以立即阅读标题/副标题。 以下代码适用于iOS4和iOS5,但在iOS5中,除非在selectAnnotation方法中将animation更改为NO,否则不会自动select注释。

任何想法为什么?

MapAnnotations *pushpin = [[MapAnnotations alloc] initWithCoordinate:coordinate]; pushpin.title = [selectedStation valueForKey:@"name"]; pushpin.subtitle = [selectedStation valueForKey:@"address"]; [stationMap addAnnotation:pushpin]; [stationMap selectAnnotation:pushpin animated:YES]; [pushpin release]; pushpin = nil; 

不知道为什么它会在以前工作,但animation可能需要注释视图被创build和准备,这是不可能立即添加注释后。

你可以做的是将select移动到应该适用于所有iOS版本的didAddAnnotationViews委托方法:

 - (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views { for (MKAnnotationView *av in views) { if ([av.annotation isKindOfClass:[MapAnnotations class]]) { MapAnnotations *pushpin = (MapAnnotations *)av.annotation; if (_this_pushpin_is_the_one_to_select) { [mapView selectAnnotation:av.annotation animated:YES]; break; //or return; } } } }