我想处理下载线程无法成功从 URL 下载图像的情况,以下代码似乎不符合我的目的:
dispatch_queue_t DownloadQueue = dispatch_queue_create("Download Pic", NULL);
dispatch_async(DownloadQueue, ^{
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:detailImageURL]];
dispatch_async(dispatch_get_main_queue(), ^{
if ([imageData isKindOfClass:[NSNull class]]) {
detailImageView.image = [UIImage imageNamed:@"no_image_available.jpg"];
}
else{
UIImage *image = [UIImage imageWithData:imageData];
detailImageView.image = image;
}
});
});
dispatch_release(DownloadQueue);