为MKAnnotationView
的文件说,这个关于其setSelected:animated:
方法(和它selected
属性类似的东西):
你不应该直接调用此方法。
相反,使用MKMapView
方法selectAnnotation:animated:
。如果您在didAddAnnotationViews
委托方法中调用它,则可以确保注记视图已准备好显示标注,否则调用selectAnnotation
将不会执行任何操作。
例如:
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
for (MKAnnotationView *av in views)
{
if ([av.annotation isKindOfClass:[MKUserLocation class]])
{
[mapView selectAnnotation:av.annotation animated:NO];
//Setting animated to YES for the user location
//gives strange results so setting it to NO.
return;
}
}
}
谢谢,这工作就像一个魅力。顺便说一下,如果使用动画,关于奇怪结果的评论是专注的。在我的应用程序中,动画会导致用户位置重置为北极(粗略)。没有动画,事情按预期工作。 – Mike 2012-01-12 23:07:11