I use UICollectionview to show many custom cells (more than 250 or less).
These cells have a main image and some text. Since the images must be downloaded from the Internet, I use the AsyncImageView external library to work with lazy downloads.
But the problem is that the reusable cell property makes me crazy.
Incorrect cells appear when scrolling images. How to add a tag or something to images other than the index path to avoid the problem?
Perhaps AsyncImageView has a solution to a problem that I ignore ...
Or is another option a better choice?
Any clue?
Thank you in advance
Edit: simplified version of my code
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ static NSString *identifier = @"Cell"; CollectionComercioCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; if (cell == nil){ } else{ [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget: cell.myImage]; } cell.myImage.imageURL = nil; cell.myImage.image = nil; cell.myImage.hidden = TRUE; cell.myImage.imageURL = [[myArray objectAtIndex:indexPath.row] getLogoUrl]; cell.myText.text = [[myArray objectAtIndex:indexPath.row] getName]; cell.myImage.hidden = FALSE; return cell;
}
CustomCell.m
- (void)prepareForReuse { [super prepareForReuse]; self.myImage.image = nil; }
source share