user3192186
user3192186

Reputation: 63

Why isn't my annotation view changing image?

I want to add a custom image for my pin, but for some reason it wont change to the newpin.png image. It still displays the default red pin. If anyone can help me I will deeply appreciate it.

 - (MKAnnotationView *)mapView:(MKMapView *)mapViewIn viewForAnnotation:(id <MKAnnotation>)annotation {
if (mapViewIn != self.mapView || [annotation isKindOfClass:[MKUserLocation class]]) {
    return nil;
}
static NSString *annotationIdentifier = @"places";
MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:annotationIdentifier];
if (!annotationView) {
    annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:annotationIdentifier];

}

annotationView.animatesDrop = YES;
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:@"newpin.png"];

UIButton *detailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[detailButton addTarget:self action:@selector(annotationDetailButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
annotationView.rightCalloutAccessoryView = detailButton;

return annotationView;
}

Upvotes: 0

Views: 95

Answers (1)

Duncan C
Duncan C

Reputation: 131491

Unless I'm mistaken, the MKPinAnnotationView class only displays pins, not other types of images. Try creating an MKAnnotationView object instead.

Upvotes: 2

Related Questions