I have UICollectionViewone that can contain up to 1000 UICollectionViewCells. When I call reloadItemsAtIndexPaths:depending on the number of cells in the collection view, it may take a long time to update the user interface. I pointed out that the problem (in my code anyway) lies between reloadItemsAtIndexPaths:and collectionView:cellForItemAtIndexPath:with the help of this code:
- (void)updateIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"starting reload of row %ld", (long)indexPath.row);
[self.collectionView reloadItemsAtIndexPaths:@[indexPath]];
NSLog(@"finished reload of row %ld", (long)indexPath.row);
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"begin creating cell at row %ld", (long)indexPath.row);
NSLog(@"end creating cell at row %ld", (long)indexPath.row);
return cell;
}
(Note that I only want to update 1 indexPath at a time)
When a collection view has 5 cells, it takes only 40 ms:
2014-03-14 13:07:10.949 Fotobox[2903:60b] starting reload of row 0
2014-03-14 13:07:10.954 Fotobox[2903:60b] begin creating cell at row 0
2014-03-14 13:07:10.974 Fotobox[2903:60b] end creating cell at row 0
2014-03-14 13:07:10.989 Fotobox[2903:60b] finished reload of row 0
But with cell 316, it takes 3.4s:
2014-03-14 13:08:48.222 Fotobox[2903:60b] starting reload of row 0
2014-03-14 13:08:51.679 Fotobox[2903:60b] begin creating cell at row 0
2014-03-14 13:08:51.708 Fotobox[2903:60b] end creating cell at row 0
2014-03-14 13:08:51.725 Fotobox[2903:60b] finished reload of row 0
Is there anything you can do to speed it up?
I assume this is internal to the UICollectionView, but I would like to be proved wrong.
Thank.