Reputation: 678
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;
}
Upvotes: 2
Views: 2498
Reputation:
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 didAddAnnotationViews
delegate method:
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
//Get reference to annotation you want to select...
//You could search through mapView.annotations array
//or keep ivar reference to it.
id<MKAnnotation> annToSelect = ...
[mapView selectAnnotation:annToSelect animated:YES];
}
Remove the performSelector
from the viewForAnnotation
method.
Upvotes: 5