I’m trying to get an MKMapView to show a pin with a callout bubble. I get the pin to display, but I just cant figure out how to display the callout.
There is my code:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation {
if (annotation == mapView.userLocation) {
return nil;
}
MKPinAnnotationView *pinView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
pinView.pinColor = MKPinAnnotationColorGreen;
[pinView setCanShowCallout:YES];
pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
pinView.animatesDrop = YES;
[self performSelector:@selector(displayPinCallOutView) withObject:nil afterDelay:0.3];
return pinView;
}
If you’re trying to get the callout to display as soon as the annotation is added to the map, you have to do it in the
didAddAnnotationViewsdelegate method:Remove the
performSelectorfrom theviewForAnnotationmethod.