更新 MKAnnotationView 中的图像
我正在编写一个应用程序,在 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];
我已经在这里寻找了一段时间,但我找不到任何可以满足我需要的东西。谢谢
I am writing an application that displays a thumbnail from a server in the leftCalloutAccessoryView. Before I actually get the image, I display a placemark image. Once the photo is downloaded, a method is called and I want to update that image without removing the original annotation and placing another. I just wan the image to switch from the placeholder to the downloaded thumbnail. Below is the code that does not work, but if someone could let me know if I'm on the right track, that would be great.
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];
I have been looking around here for quite sometime, but nothing that I can find will do what I need. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果注释已在地图上并且您想要更新它,请勿创建新注释。
相反,在地图视图的
annotations
数组中找到要更新的注释并更新其属性。然后对该现有注释调用viewForAnnotation:
并更新leftCalloutAccessoryView
。另外,请确保
viewForAnnotation
delegate 方法具有通过检查注释的属性将leftCalloutAccessoryView
设置为占位符图像或实际图像的逻辑 (并且并不总是占位符图像)。这个其他问题有一些示例代码可能会有所帮助。
If the annotation is already on the map and you want to update it, don't create a new one.
Instead, find the annotation you want to update in the map view's
annotations
array and update its properties. Then callviewForAnnotation:
on that existing annotation and update theleftCalloutAccessoryView
.Also, make sure the
viewForAnnotation
delegate method has logic that sets theleftCalloutAccessoryView
to either the placeholder image or the actual image by checking the annotation's properties (and not always the placeholder image).This other question has some sample code that may help.