I am getting problem while removing annotations from MKMapView. I have already search for same and found so many answers but couldn’t find satisfactory ans. Below is my code summary:
I have created my custom class as MyMapViewPoints and created one function as
- initWithZTitle:(NSString *)title andCoordinate:(CLLocationCoordinate2D)location
Whenever I want to add annotation I simply create one object of MyMapViewPoints and
[mapView addAnnotation:newAnnotation];
When I want to remove all mapview points (annotations) I execute following code:
for (int i =0; i < [mapView.annotations count]; i++)
{
if ([[mapView.annotations objectAtIndex:i] isKindOfClass:[MyMapViewPoints class]])
{
MyMapViewPoints *obj = (MyMapViewPoints *)[mapView.annotations objectAtIndex:i];
if(obj.type != 1)
[mapView removeAnnotation:[mapView.annotations objectAtIndex:i]];
}
}
But some of the annotation points remains on map. If I have added six points and tried to remove all using above code 2 mapview points (annotations) retains. Any ideas?
just try this code…
UPDATE:
Also try this code…