I have a map with many pins placed. I also have the following code
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView){
print("Test")
}
When I tap the pin, the function is entered correctly and "Test" is printed to the console. The problem I am facing is that, following taps of the same pin cause no execution of the above code.
To get the code to execute again, I have to tap another pin, then tap the original pin again.
How do I get the above function to fire, no matter how many times I tap the pin
The method is called when the pin is selected, not when it is tapped - though tapping it for the first time causes selection, which will remain until another pin is tapped, or the selection is cleared programmatically.
You need to deselect it before the method will be called again, using mapView.deselectAnnotation
, which you could do within the didSelect
.