Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting a MapView Annotation Twice

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.

like image 219
Philip Sheard Avatar asked Mar 26 '12 14:03

Philip Sheard


2 Answers

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.

like image 60
Mohit Manhas Avatar answered Nov 14 '22 15:11

Mohit Manhas


For those who are having this problem in '16, here is the Swift version:

mapView.deselectAnnotation(view.annotation!, animated: false)
like image 30
Karsten Avatar answered Nov 14 '22 16:11

Karsten