我一直在寻找可能是这个问题的根源,但我看不出出了什么问题。我希望你能在这里帮助我。
我正在尝试在 mapView 中显示注释,图钉被丢弃但无法看到标注,直到我先点击用户位置注释(蓝点)然后返回并点击注释,然后显示注释并一切正常。另一种方法是在引脚周围随机敲击,有时在内部敲击,运气好的话,它会显示标注。如果我在 map 上放下另一个别针,我必须执行相同的程序。
这只发生在 iOS6、模拟器和设备中。 iOS5 完美运行。
这是我用于 viewForAnnotation 的代码
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
MKAnnotationView *annotationView = nil;
//Check if this annotation is not the blue dot for user location
if(annotation != mapView.userLocation) {
//Try to rehuse a previous annotation
annotationView = (MKAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:@"searchResult"];
//If we don't have any, create it
if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"searchResult"];
}
else {//Or re use it
annotationView.annotation = annotation;
}
[annotationView setImage: [UIImage imageNamed:@"customMarker.png"]];
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.centerOffset = CGPointMake(0,-16);
annotationView.rightCalloutAccessoryView = nil;//Avoid again the detail button because is a geographic reference
}
else {//Show a text when the blue dot for user location is pressed
[mapView.userLocation setTitle:NSLocalizedString(@"you_are_here", nil)];
}
return annotationView;
}
最佳答案
我发现了问题。
我创建自定义 MKAnnotation 的方式如下:
使用这个自定义类:http://gist.github.com/3866874
然后这段代码:
MapAnnotation *location = [[MapAnnotation alloc] init];
location.title = @"some title";
location.subtitle =@"some subtitle";
location.coordinate = mapRegion.center;
location.placeData = resultSet;
[map setDelegate:self];
[map addAnnotation:location];
[map selectAnnotation:location animated:YES]; //THIS LINE WAS CAUSING THE PROBLEM IN IOS6
我刚刚删除了这条线
[map selectAnnotation:location animated:YES];
现在标注显示正确。
关于iphone - iOS6 不显示 MKAnnotationView 标注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12823046/