How to display multiple callouts from MKAnnotationView?
I like implement sth. like this. I have two annotations with callouts, but MKMapView allows only one to be selected at the same time.
[mapView selectAnnotation:self.firstAnnotation animated:F开发者_StackOverflowALSE];
[mapView selectAnnotation:self.secondAnnotation animated:FALSE];
When I select another annotation, the first one deselected automatically.
But in the picture below, it's successfully implemented. So how can this be done? http://oi52.tinypic.com/14t3t09.jpg
Also see "Multiple annotation callouts displaying in MKMapView": Multiple annotation callouts displaying in MKMapView
It appears that the framework does not support multiple selections, so you will have to implement custom callouts for this behavior. The answer to the linked question suggests making your callout a part of your annotation view so you can manage the selection yourself. Personally I like implementing the callout as an separate annotation - I have an example project with custom callouts here:
https://github.com/jacobjennings/JJMapCallout
which was my solution to:
MKAnnotationView - Lock custom annotation view to pin on location updates
In this project, I forward the MKMapView delegate methods
- (void)mapView:(MKMapView *)aMapView didSelectAnnotationView:(MKAnnotationView *)aView
- (void)mapView:(MKMapView *)aMapView didDeselectAnnotationView:(MKAnnotationView *)aView
to the respective annotation. This allows me to implement expected callout behaviors. However, you could ignore didDeselectAnnotationView messages to leave callouts visible.
To find out if the user taps on the map to clear annotations (didn't tap on a pin), check the value of mapView.selectedAnnotations in your didDeselectAnnotationView method, and if it's empty, you'll know to clear your callouts.
精彩评论