Question

I have changed my MapView pin image but I am getting this problem that some of the point wont change the pin image and some of them change. Where would be the problem? I have added an example.

My Code:

- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation
{
MKPinAnnotationView *pinAnnotation = nil;

MKAnnotationView *pinView = nil;


if(annotation != locationMap.userLocation)
{
    static NSString *defaultPinID = @"myPin";

    pinAnnotation = (MKPinAnnotationView *)[locationMap dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
    if ( pinAnnotation == nil )
        pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease];

    pinAnnotation.canShowCallout = YES;
    pinAnnotation.animatesDrop = YES;
    pinAnnotation.enabled = YES;
    //pinAnnotation.image = [UIImage imageNamed:@"pin.png"];

    pinView.image = [UIImage imageNamed:@"pin.png"];


    UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    pinAnnotation.rightCalloutAccessoryView = infoButton;
    }
    return pinAnnotation;

    return pinView;

}

Add image that show the issue

Was it helpful?

Solution

Use a regular MKAnnotationView, not the MKPinAnnotationView subclass. Even though you can set the image it isn't guaranteed to stick because it can and will set the pin image back again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top