我正在尝试从网址加载PNG,但我总是收到nil
数据。
以下是我的代码。
dispatch_async(dispatch_get_global_queue(0,0), ^{
NSData * data = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: _artworkCollectionsArray[indexPath.row].imageUrl]];
if ( data == nil ){
artworksCollectionCell.artworkImageView.image = [UIImage imageNamed:@"image-unavailable"];
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
// WARNING: is the cell still using the same data by this point??
artworksCollectionCell.artworkImageView.image = [UIImage imageWithData: data];
});
});
我还尝试使用setImageWithURL
库中的set-image
artworksCollectionCell.artworkImageView sd_setImageWithURL:[NSURL URLWithString:_artworkCollectionsArray[indexPath.row].imageUrl] placeholderImage:NO_IMAGE];
但是也无法加载任何图像。