Reputation: 63
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
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