在MKMapView上刷新MKAnnotationView [英] Refresh MKAnnotationView on a MKMapView

查看:337
本文介绍了在MKMapView上刷新MKAnnotationView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的自定义MKAnnotationView异步加载图像;我已经在使用EGOImageView-framework(它与UITableViews配合得很好),但是我无法使其在MKMapView上工作.图片似乎已加载,但我无法在地图上刷新它们-[myMap setNeedsDisplay]不执行任何操作.

I'd like to a-synchronically load images for my custom MKAnnotationView; I'm already using the EGOImageView-framework (it goes very well with UITableViews), but I fail to make it work on MKMapView. Images seem to be loaded, but I cannot refresh them on the map - [myMap setNeedsDisplay] does nothing.

推荐答案

我自己还没有尝试过,但它可能会起作用:
使用MKMapView - (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)annotation方法获取注释视图,并为其设置新图像.

I haven't tried it myself, but it might work:
Get a view for annotation using MKMapView - (MKAnnotationView *)viewForAnnotation:(id <MKAnnotation>)annotation method and set new image to it.

我自己尝试过这种方法,这种方法对我来说很有效:

Tried to do that myself and this approach worked fine for me:

//  Function where you got new image and want to set it to annotation view
for (MyAnnotationType* myAnnot in myAnnotationContainer){
    MKAnnotationView* aView = [mapView viewForAnnotation: myAnnot];
    aView.image = [UIImage imageNamed:@"myJustDownloadedImage.png"];
}

调用此方法后,所有注释图像均已更新.

After calling this method all annotations images were updated.

这篇关于在MKMapView上刷新MKAnnotationView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆