Custom annotationView bilder tilbake til pinnene når klikket

stemmer
2

Jeg viser egne bilder på et kart (i stedet for standard pins) ved hjelp av koden under. Men når jeg trykker på en vare (og bildeforklaring vises), går bildet til standard røde pinnen. Hvordan kan jeg holde min egendefinert bilde, selv når callout vises?

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

    if (annotation != mapView.userLocation) 
    {
        static NSString *pinID = @mapPin;
        pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pinID];
        if (pinAnnotation == nil)
            pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinID] autorelease];

        // Set the image
        pinAnnotation.image = [UIImage imageNamed:@TestIcon.png];

        // Set ability to show callout
        pinAnnotation.canShowCallout = YES;

        // Set up the disclosure button on the right side
        UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinAnnotation.rightCalloutAccessoryView = infoButton;

        [pinID release];
    }

    return pinAnnotation;
    [pinAnnotation release];
}
Publisert på 04/04/2010 klokken 23:08
kilden bruker
På andre språk...                            


2 svar

stemmer
5

Jeg fant ved å gjøre pinAnnotation en MKAnnotationView snarere enn en MKPinAnnotationView, jeg fikk det ønskede resultat. Bilde ikke slå inn en pinne lenger

    static NSString *pinID = @"mapPin";
    pinAnnotation = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:pinID];
    if (pinAnnotation == nil)
        pinAnnotation = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:pinID] autorelease];

    // Set the image
    pinAnnotation.image = [UIImage imageNamed:@"TestIcon.png"];
Svarte 23/11/2010 kl. 07:47
kilden bruker

stemmer
0

Du må bruke en subview snarere enn bildet eiendom. Denne koden succssfully løser problemet for meg:

    UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
    [annView addSubview:imageView];
Svarte 20/05/2010 kl. 11:53
kilden bruker

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more