我不知道我做错了什么,但它就是行不通。
我的mapView: viewForAnnotation:
样子是这样的:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
MKAnnotationView *aView = [mapView dequeueReusableAnnotationViewWithIdentifier:@"ImageMapView"];
if (!aView)
{
aView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"ImageMapView"];
aView.canShowCallout = YES;
aView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
aView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
}
[(UIImageView *)aView.leftCalloutAccessoryView setImage:nil];
aView.annotation = annotation;
return aView;
}
因此,每个新注释都以左侧标注中的空白图像视图开始。
现在,当触摸标注时,将执行下一个代码:
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
//loading an image
[(UIImageView *)view.leftCalloutAccessoryView setImage:image];
}
在日志记录的帮助下,我知道图像的 url 和数据都可以,图像本身不是零,但左侧标注中没有显示任何内容。
谁能建议我如何追查这个问题的根源?
编辑
我添加了一些日志,所以我可以看到发生了什么:
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
UIImage *image = [self.delegate imagesMapViewController:self thumbnailForAnnotation:view.annotation];
NSLog(@"Image was: %@", [(UIImageView *)view.leftCalloutAccessoryView image]);
NSLog(@"Image received: %@", image);
[(UIImageView *)view.leftCalloutAccessoryView setImage:image];
NSLog(@"Image became: %@", [(UIImageView *)view.leftCalloutAccessoryView image]);
}
我最终得到下一个输出:
Image was: (null)
Image received: <UIImage: 0x7933470>
Image became: <UIImage: 0x7933470>
所以图像正在设置,但没有出现,我不知道为什么。此外,第一个日志记录信息仅在录制第二个注释视图后才出现,因此第一个注释视图没有调用是很不寻常的mapView: didDeselectAnnotationView:
当我把
[(UIImageView *)aView.leftCalloutAccessoryView setImage:[self.delegate imagesMapViewController:self thumbnailForAnnotation:aView.annotation]];
代替
[(UIImageView *)aView.leftCalloutAccessoryView setImage:nil];
在mapView: viewForAnnotation:
所有左侧标注配件中都有应有的图像,但我想根据需要下载图像