Monday, December 23, 2013
Thursday, December 12, 2013
Monday, December 2, 2013
SDWebImage Retry Failed Image Download https://github.com/rs/SDWebImage/issues/465
SDWebImage Retry Failed Image Download
What is the best way to retry a failed image download? I have a collection view that can show about 20 80x80 thumbnail images. I put the SDWebImage code in the cellForItemAtIndexPath method, but I've found that every so often an image fails to download. I know I can use a completion block and test if the image is nil, but it doesn't seem to be reloading the image correctly (the image still never shows up). Is this how I should be handling retrying the image download? Here's an example of my code.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { NSURL *thumbnailURL = [NSURL URLWithString:url]; INCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath]; [cell.imageView setImageWithURL:thumbnailURL completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) { if (!image) { [self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]]; } }]; return cell; }
You need to use one of the methods with an "options" parameter and specify SDWebImageRetryFailed like so...
[cell.imageView setImageWithURL:thumbnailURL
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
options:SDWebImageRetryFailed
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType) {...}];
-M.
Great, thank you