在MKMapView上刷新MKAnnotationView

coc*_*est 29 iphone cocoa-touch refresh mkmapview

我想为我的自定义MKAnnotationView同步加载图像; 我已经在使用EGOImageView框架了(它与UITableViews非常相似),但是我无法在MKMapView上运行它.图像似乎已加载,但我无法在地图上刷新它们 - [myMap setNeedsDisplay]什么都不做.

Vla*_*mir 35

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

编辑:尝试自己这样做,这种方法对我来说很好:

//  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"];
}
Run Code Online (Sandbox Code Playgroud)

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


iva*_*oid 14

我找到了一种更新注释的可靠方法,其他方法对我来说不起作用:只需再次删除和添加注释:

id <MKAnnotation> annotation;

// ...

[mapView removeAnnotation:annotation];
[mapView addAnnotation:annotation];
Run Code Online (Sandbox Code Playgroud)

此代码将再次调用 - [mapView:viewForAnnotation:],因此将使用正确的数据再次创建注释视图(或者如果使用dequeueReusableAnnotationViewWithIdentifier,则可以重用).