0

I have a problem with the custom image on MapKit annotation. Building a sample project where I am performing the same test, it works properly (although the drop effect and the custom image do not work).

But when I use exactly the same function on my map view project, the custom image does not appear. I noticed that the color pin change function MKPinAnnotationColorPurple does not work either. Is it possible that it depends on some project properties?

The code is:

-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    static NSString *identifier = @"MyLocation";   

    if ([annotation isKindOfClass:[MyLocation class]]) {

        MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

        if (annotationView == nil) {
            annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        } else {
            annotationView.annotation = annotation;
        }
        annotationView.enabled = YES;
        annotationView.animatesDrop=    NO;
        annotationView.image=[UIImage imageNamed:@"arrest.png" ];//here we use a nice image instead of the default pins


        annotationView.canShowCallout = YES;
        UIButton *btnDetails = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        //[btnDetails addTarget:self action:@selector(prova) forControlEvents:UIControlEventTouchUpInside]; 

        annotationView.rightCalloutAccessoryView=btnDetails;

        return annotationView;
    }

    return nil;
}

The UIButtonTypeDetailDisclosure does not appear either (in other projects it does).

Pang
  • 9,564
  • 146
  • 81
  • 122
doxsi
  • 1,002
  • 19
  • 42
  • What exactly works "properly" in the sample project and not in the actual project? Is the map view's delegate property or outlet set? Post the method that works in the sample but not in the actual. –  May 23 '12 at 16:34
  • You need to provide some extra info. Actual code would even be very useful to help you. – Cyril Godefroy May 23 '12 at 18:28
  • 1
    The method looks fine except that it should create an MKAnnotationView instead of MKPinAnnotationView since you are using a custom image (see http://stackoverflow.com/questions/9814988/mkmapview-instead-of-annotation-pin-a-custom-view). However, the callout button should appear regardless. Check that the map's delegate is set and that you are adding an annotation of type MyLocation. Put a breakpoint or NSLog on the line that sets rightCalloutAccessoryView to make sure it's getting called. –  May 24 '12 at 02:07
  • Thanks for answer...About the annotation, in my other project (where MKPinAnnotationView works), the difference is (apparently) only about the use of storyboard while in the currently project I am using a nib file. where could check if the map's delegate is set ? about the rightCalloutAccessoryView yes, the callback works but no button appear... – doxsi May 24 '12 at 14:22

0 Answers0