【发布时间】:2014-09-09 05:17:24
【问题描述】:
您好,我正在使用 SDWebImage 将远程图像加载到我的集合视图中。 第一次它的加载很好,就像第一次显示占位符图像并且当图像被检索然后更改单元格的图像...但是第二次我加载相同的图像时,顶部可见行没有显示图像但是当我向下滚动到其他图像时,它们加载正常。然后我加载回顶部,图像就在那里。
在我的 collectionview 类中 -
- (void)startIconDownload:(TrialImages *)appRecord forIndexPath:(NSIndexPath *)indexPath
{
TrialPicDownloader *iconDownloader = [_imageDownloadsInProgress objectForKey:indexPath];
if (iconDownloader == nil)
{
iconDownloader = [[TrialPicDownloader alloc] init];
iconDownloader.productRecord = appRecord;
[iconDownloader setCompletionHandler:^{
MyCollectionViewCell *cell = (MyCollectionViewCell *)[self.myCollectionView cellForItemAtIndexPath:indexPath];
cell.trialImageView.image = appRecord.trialImage;
[_imageDownloadsInProgress removeObjectForKey:indexPath];
}];
[_imageDownloadsInProgress setObject:iconDownloader forKey:indexPath];
[iconDownloader startDownload];
}
}
此方法在 TrialPicDownloader 类中 -
- (void)startDownload
{
[[SDWebImageManager sharedManager] downloadWithURL:
[NSURL URLWithString:self.productRecord.TrialImagesUrl]
options:SDWebImageCacheMemoryOnly
progress:nil
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
if (image != NULL) {
self.productRecord.trialImage = image;
if (self.completionHandler)
self.completionHandler();
}
}];
}
【问题讨论】:
标签: ios objective-c sdwebimage