LoginSignup
2
2

More than 5 years have passed since last update.

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

Posted at

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;
}
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2