My iPhone app has a mapview with a large number of locations that the user can select from. I would like him to be able to tap on one of the annotations to display its callout view, and then again to actually select it. The problem is that the didSelectAnnotationView only gets called once.
So how can I detect the selection an already selected annotation? Alternatively, how can I deselect an annotation without hiding the callout view? The user can work round this by deselecting the annotation before he selects it again, but this is not intuitive, and I want to avoid him having to do this.
I just found the solution with the code below:
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
[mapview deselectAnnotation:view.annotation animated:NO];
}
This way the selected annotation gets deselected and you can select it once again.
For those who are having this problem in '16, here is the Swift version:
mapView.deselectAnnotation(view.annotation!, animated: false)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With