1
votes

In my app I have two functionality when my tableview loads ,in the mapview all the pins are shown corresponding to tableData.NOw I have search bar which gives another set of values which I have to show on my mapView.Everything is working fine but second time previous pins are also shown means prevoius annotations are not deleted . So please tell me how to remove prevoius annotation so that I can show only relavent pins on mapView Thanks in advance

2

2 Answers

7
votes

Simply use the MKMapView instance method "removeAnnotations:":

-(void)removeAnnotations:(NSArray *)annotations

http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html

If you want to remove all of them you can do somethign like :

[mapView removeAnnotations:mapView.annotations];

P.S: Beware that you might want to iterate through the annotations not to remove the userLocation (blue dot)

Hope this helps, Vincent

3
votes

I got my answer my self:-

mapAddAnnotations is my arrayname and map is my mkmapview object.

[map removeAnnotations:self.mapAddAnnotations];