Force MKMapView viewForAnnotation to update

后端 未结 5 1224
忘掉有多难
忘掉有多难 2021-02-12 22:05

So I have a MKMapView with all my pins added, and the colour of the pin is dependent on whether a value is set for that pin. When I first load the app, viewForAnnotation

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-12 22:43

    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.

提交回复
热议问题