MapView: didSelectAnnotationView: not working properly.

I am creating an iOS application that uses the built-in map view. Im successfully posting custom annotations etc. However, I had a problem with the delegate function, which is called when the annotation is clicked (mapView: didSelectAnnotationView).

The first time I click on the annotation, the function is called correctly. However, if I click the same annotation again, the function does not work. If at that moment I click on another annotation, the function will shoot, but then if I click on this THAT annotation again, the function does not work. Basically, I cannot double-click the same annotation twice in a row. The delegate function will only be called for the first time. Has anyone encountered this issue? Somewhere in particular, should I look for an error?

+6
source share
3 answers

Well, when you think about it, you have already chosen this annotation view. It does not make sense for the delegate to inform you that the pin is selected if it already exists.

A simple fix might be to annotate to be canceled in the delegate call. This will allow you to call again.

[annotation setSelected:NO animated:NO]; 

Here you can find the method you need to call. https://developer.apple.com/library/ios/documentation/mapkit/reference/MKAnnotationView_Class/index.html#//apple_ref/occ/instm/MKAnnotationView/setSelected:animated :

+4
source
A friend suggested an idea, and that turned out to be right. When makeSelectAnnotationView fires, it actually marks the annotation as selected. Then, when you click on it again, the delegate function does not start because it is already selected. You must manually deselect the annotation by calling the following function as soon as you are done doing what you want.
 [mapView deselectAnnotation:view.annotation animated:false]; 
+5
source
 - (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)aView { indexPathTag=aView.tag; [mapView deselectAnnotation:aView.annotation animated:YES]; } - (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)aView { } 

I hope this works for you :) I ran into the same problem, this code worked for me.

+1
source

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


All Articles