Вопрос

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

Это было полезно?

Решение

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.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top