2
我有一个UICollectionView由Web服务支持。我最初从服务中加载100个项目到集合视图中。当用户到达视图的底部时,我用阴蒂加载下一个“页面”的内容。动态添加内容到UICollectionView
这是工作,但我collectionView闪烁并重新绘制从顶部的整个视图。我试图让它开始在视图的底部绘制新内容。
代码添加新的内容的CollectionView:
- (void)insertIntoCollectionView: (int) itemCnt {
// only do the batchupdate for NON-initial load
if(curPage != 0) {
// Add items to main photos array, and update collectionview using batchUpdate
[self.collectionView performBatchUpdates:^{
// Get starting size before update
int resultsSize = itemCnt;
// Create a new array to hold the indexpath for the inserted data
NSMutableArray *arrayWithIndexPaths = [NSMutableArray array];
// Add indexpath objects to the new array to be added to the collection view
for (int i = resultsSize; i < resultsSize + itemCnt; i++) {
[arrayWithIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
// Update the collectionview
[self.collectionView insertItemsAtIndexPaths:arrayWithIndexPaths];
}
completion:nil];
} else {
[self.collectionView reloadData];
}
curPage++;
任何明显?它在功能上起作用,但对于所有闪烁和重新绘制看起来都很糟糕。
您能否让我知道如何解决此问题?我也面临同样的问题,请让我知道你做了什么代码更改 – Nishan29
你能告诉我这个解决方案吗? – Nishan29