कस्टम annotationView छवियों जब क्लिक पिन करने के लिए वापस

वोट
2

मैं एक नक्शा (डिफ़ॉल्ट पिन के बजाय) का कस्टम चित्रों का प्रदर्शन कर रहा हूँ नीचे कोड का उपयोग कर। हालांकि, जब मैं एक आइटम पर नल (और कॉलआउट दिखाई देता है), छवि डिफ़ॉल्ट लाल पिन में बदल जाती। मैं अपने कस्टम छवि रख सकते हैं, भले ही कॉल आउट प्रदर्शित किया जाता है?

- (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];
}
05/04/2010 को 00:08
का स्रोत उपयोगकर्ता
अन्य भाषाओं में...                            


2 जवाब

वोट
5

मैं pinAnnotation एक MKAnnotationView बजाय एक MKPinAnnotationView बनाकर पाया, मैं वांछित परिणाम मिल गया। छवि अब एक पिन में बदल नहीं करता है

    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"];
23/11/2010 को 08:47
का स्रोत उपयोगकर्ता

वोट
0

आप छवि संपत्ति के बजाय एक subview उपयोग करने के लिए की जरूरत है। इस कोड को succssfully मेरे लिए समस्या का हल:

    UIImage * image = [UIImage imageNamed:@"blue_pin.png"];
    UIImageView *imageView = [[[UIImageView alloc] initWithImage:image] autorelease];
    [annView addSubview:imageView];
20/05/2010 को 12:53
का स्रोत उपयोगकर्ता

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