immagini personalizzate annotationView ritornano ai pin quando si fa clic

voti
2

Sto visualizzazione di immagini personalizzate su una mappa (al posto dei perni di default) usando il codice seguente. Tuttavia, quando toccare un elemento (e appare il richiamo), l'immagine ritorna al perno rosso predefinita. Come posso mantenere la mia immagine personalizzata, anche quando è visualizzata la didascalia?

- (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];
}
È pubblicato 05/04/2010 alle 00:08
fonte dall'utente
In altre lingue...                            


2 risposte

voti
5

Ho trovato facendo il pinAnnotation un MKAnnotationView piuttosto che un MKPinAnnotationView, ho ottenuto il risultato desiderato. Immagine non si trasformi in un perno più

    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"];
Risposto il 23/11/2010 a 08:47
fonte dall'utente

voti
0

È necessario utilizzare una visualizzazione secondaria piuttosto che la proprietà dell'immagine. Questo codice risolve succssfully il problema per me:

    UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
    [annView addSubview:imageView];
Risposto il 20/05/2010 a 12:53
fonte dall'utente

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