Uko*_*Uko 2 objective-c mapkit ios
我不知道我做错了什么,但它不会工作.
我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;
}
Run Code Online (Sandbox Code Playgroud)
所以每个新的注释都以左侧标注中的空白图像视图开始.
现在当触摸标注时,执行下一个代码:
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
{
//loading an image
[(UIImageView *)view.leftCalloutAccessoryView setImage:image];
}
Run Code Online (Sandbox Code Playgroud)
在日志记录的帮助下,我知道图像的网址和数据都没问题,图像本身也不是零,但左侧标注中没有显示任何内容.
任何人都可以建议我如何追查这个问题的根源?
我添加了一些日志,所以我可以看到发生了什么:
- (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]);
}
Run Code Online (Sandbox Code Playgroud)
我最终得到了下一个输出:
Image was: (null)
Image received: <UIImage: 0x7933470>
Image became: <UIImage: 0x7933470>
Run Code Online (Sandbox Code Playgroud)
所以图像正在设置,但没有出现,我不明白为什么.此外,第一个日志记录信息仅在第二个注释视图被录制后出现,因此第一个注释视图未调用是很不寻常的mapView: didDeselectAnnotationView:
当我放的时候
[(UIImageView *)aView.leftCalloutAccessoryView setImage:[self.delegate imagesMapViewController:self thumbnailForAnnotation:aView.annotation]];
Run Code Online (Sandbox Code Playgroud)
代替
[(UIImageView *)aView.leftCalloutAccessoryView setImage:nil];
Run Code Online (Sandbox Code Playgroud)
在mapView: viewForAnnotation:
所有左侧标注配件有他们应该的图像,但离开源我想按需下载图像
问题是,你使用
- (void)mapView:(MKMapView *)mapView didDeselectAnnotationView:(MKAnnotationView *)view
Run Code Online (Sandbox Code Playgroud)
什么时候应该使用
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
Run Code Online (Sandbox Code Playgroud)
干杯)
归档时间: |
|
查看次数: |
4759 次 |
最近记录: |