我正在注释我的地图并设置好图像,但是当我点击MapView上的注释时,图像会从我的自定义图像返回到红色图钉.为什么是这样?
- (MKAnnotationView *)mapView:(MKMapView *)newMapView viewForAnnotation:(id )newAnnotation {
MKPinAnnotationView *annotation = [[MKPinAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:@"currentloc"];
if (annotation == nil) {
annotation = [[MKAnnotationView alloc] initWithAnnotation:newAnnotation reuseIdentifier:@"currentloc"];
}
annotation.image = [UIImage imageNamed:@"anno.png"];
annotation.canShowCallout = YES;
annotation.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bus_stop_30x30.png"]];
annotation.leftCalloutAccessoryView = imgView;
return annotation;
}Run Code Online (Sandbox Code Playgroud)
我的代码看起来与一些不会产生此问题的示例代码相同.
我有一个分段控制器,它位于MKMapView上.当我更改MKMapType时,我的自定义引脚的图像将恢复为默认的红色.标题和副标题以及坐标保持不变.任何人都可以对可能的解决方案有所了解吗?