0

When scrolling through a UICollectionView, it seems that not everything in cellForItemAtIndexPath gets called consistently. I'm wondering if it's because the cell gets recycled before the method can complete.

For instance (I'm using the UIImageView category from AFNetworking):

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
THMovieCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

NSNumber* position = [[NSNumber alloc] initWithInteger:indexPath.row + 1];
THMovie* movie = [self.Movies objectForKey:position];

if (movie.ImageUrl) {
    [cell.Cover setImageWithURL:movie.ImageUrl];
}

cell.Title.text = movie.Title;

return cell;
}

...however while the cell.Title UILabel in my custom cell is consistently changed, the image is not.

What's the best way of improving performance for fast scrolling through cells?

James
  • 6,471
  • 11
  • 59
  • 86
  • Is your question about performance, or about the bug with the image view? Cells get re-used and unless AFNetworking is doing something special to account for this you're going to see inconsistent behavior if you associate an image with a cell, instead of an index path. If it's about performance, maybe you could share what slowdowns you've found in Instruments. Right now, it's not really clear what the question is about so hard to make recommendations. – Carl Veazey Jan 20 '13 at 04:09
  • Scrolling problem,please refer 3 links: http://stackoverflow.com/questions/14204204/update-uiprogressview-in-uicollectionviewcell-for-download-file/14301380#14301380 – LE SANG Jan 21 '13 at 08:08

1 Answers1

0

It's hard to tell without knowing about THMovieCell internals but still. You set image URL to movie.ImageUrl. If it is a remote URL and its image is not already cached somehow slow updates of cover are inevitable, because it have to load this image. Another possible reason is image size. If you have 10 images 1024x1024 squeezed in the screen this can cause a great lag on scrolling.

  1. Check your image cache performance if any. Make it asynchronous, cancel any image loading operation which is not required because movie is already out of screen.
  2. Check image sizes. Use thumbnails whenever possible.
  3. Set cover's image to default local image indicating loading process and only after that set new image URL. This way user will be notified that cover is about to change.
  4. Fix your cover updating logic. Now if movie doesn't have image then cell's image will not be updated and will continue to show image of the previous movie it was used for.
hoha
  • 4,418
  • 17
  • 15