Force MKMapView viewForAnnotation to update Force MKMapView viewForAnnotation to update ios ios

Force MKMapView viewForAnnotation to update


Actually, I dont' know if this worked for you but this is how I did it.

I didn't need to delete the annotation from map. All I need to do is tell the map to give me the annotation view for a parameter annotation. The map will return the correct annotation. From there, I have a property for my custom annotation to identify whether it is an active item, if yes, show the normal pin image, else show full pin image.

-(void)updateAnnotationImage:(CustomAnnotation *)paramAnnotation{    MKAnnotationView *av = [geoMap viewForAnnotation:paramAnnotation];    if (paramAnnotation.active)    {        av.image = [UIImage imageNamed:@"PinNormal.png"];    }    else    {        av.image = [UIImage imageNamed:@"PinFull.png"];    }}

Bit late but hopefully it helps others who came across this problem.


Due to the way the map view caches its annotations, you NEED to remove and re-add the annotation if you need to make changes to its appearance. A simple remove & add is the way to go. There is no cache invalidating mechanism but this.


I also found this answer helpful: In which case that mapView:viewForAnnotation: will be called?

Whenever you call addAnnotation method

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id < MKAnnotation >)annotation gets called.