简体   繁体   中英

iOS6 not showing MKAnnotationView callout

I've been searching around what can be the source of this problem, but I can't see what's going wrong. I hope you can help me here.

I'm trying to show an annotation in a mapView, the pin is dropped but is impossible to see the callout until I tap first the user location annotation (blue dot) and then go back and tap the annotation, then the annotation is displayed and everything work fine. Another way is to randomly tap around the pin and sometimes inside and with some luck it will show the callout. If I drop another pin on map, I have to do the same procedure.

This only happens in iOS6, simulator and device. iOS5 works perfectly.

This is the code I'm using for the viewForAnnotation

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

    MKAnnotationView *annotationView = nil;

    //Check if this annotation is not the blue dot for user location
    if(annotation != mapView.userLocation) {

        //Try to rehuse a previous annotation
        annotationView = (MKAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:@"searchResult"];

        //If we don't have any, create it
        if (annotationView == nil) {
            annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"searchResult"];
        }
        else {//Or re use it
            annotationView.annotation = annotation;
        }


        [annotationView setImage: [UIImage imageNamed:@"customMarker.png"]];
        annotationView.enabled = YES;
        annotationView.canShowCallout = YES;
        annotationView.centerOffset = CGPointMake(0,-16);
        annotationView.rightCalloutAccessoryView = nil;//Avoid again the detail button because is a geographic reference


    }
    else {//Show a text when the blue dot for user location is pressed
        [mapView.userLocation setTitle:NSLocalizedString(@"you_are_here", nil)];
    }

    return annotationView;

}

I found the problem.

The way I was creating my custom MKAnnotation was the following:

Using this custom class: http://gist.github.com/3866874 Then this code:

MapAnnotation *location = [[MapAnnotation alloc] init];
location.title = @"some title";
location.subtitle =@"some subtitle";
location.coordinate = mapRegion.center;
location.placeData = resultSet;
[map setDelegate:self];
[map addAnnotation:location];
[map selectAnnotation:location animated:YES]; //THIS LINE WAS CAUSING THE PROBLEM IN IOS6

I just removed the line

[map selectAnnotation:location animated:YES];

and now the callout is shown correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM