Search code examples
iosobjective-cuicollectionviewgrand-central-dispatch

The best way to update multiple cells in a collection view?


I have a collection view with a flow layout that shows multiple cells. Every cell has some async loading happening before it displays an image and some text. What is the best way to update these cells in succession?

I am doing something like this that works but I'm noticing my collection view gets frozen for a second or so if multiple cells get finished at the same time.

dispatch_async(dispatch_get_main_queue(), ^{
    [collectionView reloadItemsAtIndexPaths:@[indexPath]];
});

Solution

  • It would be nice to add some more of your code, But it is actually better to do this kinda stuff with performBatchUpdates instead of doing it in main thread.

    - (void)performBatchUpdates:(void (^)(void))updates completion:(void (^)(BOOL finished))completion;

    Here is the documentation