Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to close a callout for MKAnnotation in a MKMapView

Tags:

I have a MKMapView that has a number of annotations. Selecting the pin displays the callout and pressing the accessory pops a new viewcontroller onto the stack. However when I press back from that new VC the callout is still open. How do I close it?

I have tried

if([[myMapView selectedAnnotations] count] > 0)
{
    //deselect that annotation
    [myMapView deselectAnnotation:[[myMapView selectedAnnotations] objectAtIndex:0] animated:NO];
}

but this does not work. The selectedAnnotations does have a single entry in the array so it does go into this statement but the callout is not closed.

Do I need to add something to my MKAnnotation implementation or my MKPinAnnotationView?

like image 760
joneswah Avatar asked Jul 28 '09 12:07

joneswah


1 Answers

The objects in selectedAnnotations are instances of MKAnnotation

NSArray *selectedAnnotations = mapView.selectedAnnotations;
for(id annotation in selectedAnnotations) {
    [mapView deselectAnnotation:annotation animated:NO];
}
like image 172
afunishi Avatar answered Oct 27 '22 23:10

afunishi