joneswah joneswah - 1 year ago 105
Objective-C Question

How to close a callout for MKAnnotation in a MKMapView

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?


The objects in selectedAnnotations are instances of MKAnnotation

NSArray *selectedAnnotations = mapView.selectedAnnotations;
for(id annotation in selectedAnnotations) {
    [mapView deselectAnnotation:annotation animated:NO];