How to display multiple callouts from MKAnnotationView?

I like to implement sth. like this. I have two annotations with callouts, but MKMapView allows you to select only one at a time.

[mapView selectAnnotation:self.firstAnnotation animated:FALSE]; [mapView selectAnnotation:self.secondAnnotation animated:FALSE]; 

When I select another annotation, the first is automatically canceled.

But in the figure below, it has been successfully implemented. So how can this be done? http://oi52.tinypic.com/14t3t09.jpg

+6
source share
1 answer

Also see "Displaying Multiple Annotations in MKMapView": Displaying Multiple Annotations in MKMapView

It seems that the framework does not support multiple selections, so you will have to implement custom callouts for this behavior. The answer to a related question suggests making your callout part of your annotation view so that you can manage your choices yourself. Personally, I like to implement callout as a separate annotation - I have an example project with custom callouts here:

https://github.com/jacobjennings/JJMapCallout

which was my solution:

MKAnnotationView - block user annotation view for binding to location updates

In this project, I am sending MKMapView delegation methods

 - (void)mapView:(MKMapView *)aMapView didSelectAnnotationView:(MKAnnotationView *)aView - (void)mapView:(MKMapView *)aMapView didDeselectAnnotationView:(MKAnnotationView *)aView 

to the corresponding annotation. This allows me to implement the expected callout behavior. However, you can ignore didDeselectAnnotationView messages to display them.

To find out if the user is deleting on the map in order to clear annotations (do not click on a contact), check the value of mapView.selectedAnnotations in your didDeselectAnnotationView method, and if it is empty, you will know to clear the callouts.

+5
source

Source: https://habr.com/ru/post/893368/


All Articles