Question

So I understand the concept of reusing cells for tableviews and such but I am having a terrible time with a custom item within an SSCollectionViewItem. Here is the code I am using:

- (SSCollectionViewItem *)collectionView:(SSCollectionView *)aCollectionView itemForIndexPath:(NSIndexPath *)indexPath {
static NSString *const itemIdentifier = @"itemIdentifier";

StoryCollectionViewItem *item = (StoryCollectionViewItem *)[aCollectionView dequeueReusableItemWithIdentifier:itemIdentifier];

if(item == nil){
item = [[StoryCollectionViewItem alloc] initWithReuseIdentifier:itemIdentifier];
}
    NSString *sURL = [[featuredStories objectAtIndex:indexPath.row] objectAtIndex:1];
    NSURL *url = [NSURL URLWithString:sURL];

[item.card.imageView setImageWithURL:url placeholderImage:nil];

return item;
}

It seems to 'kinda' work but unfortunately not perfectly. What I'm getting is about 80% of the cells loading correctly but the rest only loading after they disappear on the screen then reappear. Here are some screenshots:

Cells not loaded After they reappear on screen

Was it helpful?

Solution

I had that problem before, but then i override the prepareForReuse method and set an placeholder imagem and it got fixed

OTHER TIPS

While I cannot say for sure, I would suggest that the way you set images here is quite non-standard. The cells are getting recycled constantly as the table moves. A better way to do what you want (but more complicated) is to keep a cache of images associated with a tag (which could be the indexPath of the cell.

When you are asked for a cell, you provide it, and if you have the image you set it immediately. If you don't have it, you issue a fetch for the cell, and when you get it, you add it to your cache, then see if the cell that needs it is now visible (by asking the tableView), and if its visible you then set it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top