imagini annotationView personalizate reveni la ace, atunci când a făcut clic

voturi
2

Sunt afișarea imaginilor pe o hartă (în locul știfturilor implicite), folosind codul de mai jos. Cu toate acestea, atunci când am apăsați pe un element (și apare înștiințarea), imaginea revine la PIN-ul roșu implicit. Cum pot păstra imaginea mea personalizată, chiar și atunci când este afișat înștiințarea?

- (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];
}
Întrebat 05/04/2010 la 00:08
sursa de către utilizator
În alte limbi...                            


2 răspunsuri

voturi
5

Am găsit prin a face o pinAnnotation MKAnnotationView, mai degrabă decât un MKPinAnnotationView, am primit rezultatul dorit. Imaginea nu se mai transforma într-un cod PIN

    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"];
Publicat 23/11/2010 la 08:47
sursa de către utilizator

voturi
0

Trebuie să utilizați un subview mai degrabă decât proprietatea de imagine. Acest cod rezolvă problema succssfully pentru mine:

    UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
    [annView addSubview:imageView];
Publicat 20/05/2010 la 12:53
sursa de către utilizator

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