0

I have this very nice collectionview that loads pictures from my server. Now, if the pictures are loading slowly, the collectionview is actually scrollable, but if the pictures are loading fast, instead, the collectionview is basically frozen until all the cells are finally loaded.

I'm pretty sure this is something related to the fact that I'm using dispatch_async to update the ui (inserting cells and sections), so I'm wondering if there's a way to update the ui that still allows me to scroll the collectionview while the items are being added.

Is there anything I'm missing?

Thanks in advance for your help!

overkill
  • 103
  • 2
  • 8

1 Answers1

0

The easiest way to solve this issue is to use SDWebImage an UIImageView alternative , and call the sd_setImageWithURL:placeholderImage: method from the tableView:cellForRowAtIndexPath: UITableViewDataSource method. Everything will be handled for you, from async downloads to caching management.

You can find it here: https://github.com/rs/SDWebImage

So remove any dispatch_async, set right away the number of cells on this method:

- (NSInteger)numberOfItemsInSection:(NSInteger)section;

Scroll performance is going to be good with this tool

metronic
  • 455
  • 5
  • 15
  • unfortunately I doubt this is a feasable solution, as the pictures I'm downloading from the server are not publicly available... – overkill Feb 01 '16 at 20:11
  • That should not be a serious issue because you can set custom HTTP headers as shown here: http://stackoverflow.com/a/16708976/470424 – metronic Feb 01 '16 at 20:26