In my method cellForItemAtIndexPath i have this code:
SDWebImageManager *manager = [SDWebImageManager sharedManager];
[manager downloadWithURL:[NSURL URLWithString:coverURL] options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
} completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished) {
RRRBigItemCell *cell = (RRRBigItemCell *)[collectionView cellForItemAtIndexPath:indexPath];
if (cell) {
RRRImageView *coverView = (RRRImageView *)[cell viewWithTag:COVER_TAG];
coverView.image = image;
}
}];
When i launch application and i scroll down then everything is ok. But when i scroll up than cell which were already displayed don't have loaded images (cell == nil). And if i again scroll down the problem remains for already displayed cells, only new ones have loaded images. Any idea what i'm doing wrong?
@pawan is correct, that would be simplest way to implement SDWebImage. It's basically a category of UIImage, so simply use the category methods (setImageWithURL).
A couple of other points since you asked;
In your code, you should be setting the coverImage.image on the main thread, not in the background.
It's good practice to check if the Cell is visible, or there is little point in displaying the content.
It's good practice to create a weak reference to the Collection view when accessing the cell to avoid circular references
so your code ) might be written as follows if you were insistent on doing it the way you have it (Using the category is the best and simplest way)
why dont you try this
[cell.imageView setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"] placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
reference SDWebImage