Posted at

iOS9でMKMapViewのピンのアイコン画像が表示されなくなった時の対処方法

More than 3 years have passed since last update.

MKPinAnnotationViewでなく、MKAnnotationViewを使います。

Before

-(MKAnnotationView*)mapView:(MKMapView*)mapView

viewForAnnotation:(id)annotation{

CustomAnnotation* ca = (CustomAnnotation*)annotation;

static NSString *PinIdentifier = @"Pin";
MKPinAnnotationView* av = (MKPinAnnotationView *)[mapView
dequeueReusableAnnotationViewWithIdentifier:PinIdentifier];

if (!av) {
av = [[MKPinAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:PinIdentifier];
av.canShowCallout = YES;
av.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}

av.image = [UIImage imageNamed:@"image.png"];
av.annotation = annotation;

return av;
}

After

-(MKAnnotationView*)mapView:(MKMapView*)mapView

viewForAnnotation:(id)annotation{

CustomAnnotation* ca = (CustomAnnotation*)annotation;

static NSString *PinIdentifier = @"Pin";
MKAnnotationView * av = (MKAnnotationView *)[mapView
dequeueReusableAnnotationViewWithIdentifier:PinIdentifier];

if (!av) {
av = [[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:PinIdentifier];
av.canShowCallout = YES;
av.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}

av.image = [UIImage imageNamed:@"image.png"];
av.annotation = annotation;

return av;
}