我正在编写一个应用程序,它在 leftCalloutAccessoryView 中显示来自服务器的缩略图。在我真正得到图像之前,我会显示一个地标图像。下载照片后,将调用一个方法,我想在不删除原始注释并放置另一个注释的情况下更新该图像。我只是想让图像从占位符切换到下载的缩略图。下面是不起作用的代码,但如果有人可以让我知道我是否走在正确的轨道上,那就太好了。
MyAnnotationClass *annotation=[[MyAnnotationClass alloc] initWithCoordinate:item.location];
[annotation setItem:item];
if(item.title){
annotation.name=item.title;
}
else{
annotation.name=@"no title";
}
[annotation setDescription:[[NSString alloc] initWithFormat:@"Views:%d Likes:%d Comments:%d",item.views,item.likes,item.comments]];
[annotation setImage:[[photo.thumb copyWithDimensions: CGSizeMake(32.0, 32.0)] autorelease]];
MKAnnotationView *av=[__mapView viewForAnnotation:annotation];
UIImageView *imageView=[[UIImageView alloc] initWithImage:annotation.image];
imageView.frame=CGRectMake(0.0, 0.0, 32.0, 32.0);
av.leftCalloutAccessoryView=imageView;
[annotation release];
我已经在这里寻找了很长一段时间,但我找不到任何东西可以满足我的需要。谢谢
最佳答案
如果注记已经在 map 上并且您想要更新它,请不要创建新注记。
相反,请在 map View 的 annotations
中找到您要更新的注释。数组并更新其属性。然后调用viewForAnnotation:
在该现有注释上并更新 leftCalloutAccessoryView
.
另外,请确保 viewForAnnotation
委托(delegate)方法具有设置 leftCalloutAccessoryView
的逻辑通过检查注释的属性(并不总是占位符图像),将占位符图像或实际图像。
This other question有一些示例代码可能会有所帮助。
关于iphone - 在 MKAnnotationView 中更新图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7128760/