0
我设立一个MapView的注释时,我的地图视图显示以下代码,这一切似乎除了选择工作正常:为什么selectAnnotation在这种情况下不起作用?
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
MapAnnotation *pinpoint = [[MapAnnotation alloc] initWithTitle:@"Title" andCoordinate:loc];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(loc, 1500, 1500);
[self.mapView setRegion:region animated:true];
[self.mapView addAnnotation:pinpoint];
[self.mapView selectAnnotation:pinpoint animated:true]; //nothing happens!?
}
但如果调用这个回调同样的方法,它工作正常:
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views
{
MKAnnotationView *annotationView = [views objectAtIndex:0];
id <MKAnnotation> mp = [annotationView annotation];
[mv selectAnnotation:mp animated:YES];
}
这是什么原因造成的?这只是不适合调用selectAnnotation的地方吗?我是否必须等待viewForAnnotation被调用后?
我在其他问题的解决:http://stackoverflow.com/a/13026353/736384 – 2012-10-23 08:33:51