Search code examples
iphonecrashmapkitmkannotation

Problem removing annotation from mapView


I am storing all the annotations I am adding in a separate array. When I try to remove an annotation that has been added to the mapView using the following code:

if(![newClusters containsObject:cluster]){
    [__mapView removeAnnotations:[__clusterAnnotations objectAtIndex:[__clusters indexOfObject:cluster]]];
    [__clusterAnnotations removeObjectAtIndex:[__clusters indexOfObject:cluster]];
    [__clusters removeObject:cluster];
}

I get the following error:

-[ClusterAnnotationClass countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance

I'm not sure what this means, and I can add in any annotation just fine. It crashes when removing from the mapView.

Any help would be appreciated.


Solution

  • You are calling removeAnnotations (plural) which takes an array of annotations but it looks like the object you are passing it is not an array.

    Perhaps you meant to call removeAnnotation (singular)?