UICollectionView reloadItemsAtIndexPaths因大量UICollectionViewCells而变慢

时间:2014-03-14 13:16:55

标签: ios objective-c uicollectionview

我有一个UICollectionView,最多可以加载UICollectionViewCells reloadItemsAtIndexPaths:。当我根据集合视图中的单元格数量调用reloadItemsAtIndexPaths:时,更新UI可能需要很长时间。我已经确定问题(在我的代码中无论如何)使用此代码位于collectionView:cellForItemAtIndexPath:- (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); // Customise the cell NSLog(@"end creating cell at row %ld", (long)indexPath.row); return cell; } 之间:

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

(请注意,我一次只想更新1个indexPath)

当集合视图有5个单元格时,它只需要40毫秒:

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

但对于316细胞而言需要3.4s:

{{1}}

我有什么办法可以加快速度吗?
我猜这是UICollectionView的内部信息,但我希望被证明是错误的。

感谢。

0 个答案:

没有答案
相关问题