Ios 向UICollectionView动态添加内容

Ios 向UICollectionView动态添加内容,ios,uicollectionview,collectionview,Ios,Uicollectionview,Collectionview,我有一个由web服务支持的UICollectionView。我最初将100个项目从服务加载到集合视图中。当用户到达视图的底部时,我会动态加载下一个“页面”的内容 这是可行的,但我的collectionView会闪烁并从顶部重新绘制整个视图。我试图让它在视图的底部开始绘制新内容 用于向collectionview添加新内容的代码: - (void)insertIntoCollectionView: (int) itemCnt { // only do the batchupdate for NO

我有一个由web服务支持的UICollectionView。我最初将100个项目从服务加载到集合视图中。当用户到达视图的底部时,我会动态加载下一个“页面”的内容

这是可行的,但我的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++;
-(void)insertIntoCollectionView:(int)itemCnt{
//仅对非初始加载执行批处理更新
如果(curPage!=0){
//将项目添加到主照片阵列,并使用batchUpdate更新collectionview
[self.collectionView性能更新:^{
//更新前获取起始大小
int resultsSize=itemCnt;
//创建一个新数组来保存插入数据的indexpath
NSMutableArray*ArrayWithindExpath=[NSMutableArray];
//将indexpath对象添加到要添加到集合视图的新数组中
对于(int i=resultsSize;i

有什么明显的问题吗?它在功能上是有效的,但在所有的闪烁和重新绘制中看起来都很糟糕。

好的,我自己设法解决了。我对resultSize变量使用了不正确的值。for循环应该从当前数组计数的末尾开始,然后循环我们添加的项数,从而在末尾添加它们。在构建阵列时,我从阵列索引1的开头开始创建了一个具有扩展路径的阵列,导致它重新绘制整个视图。

您能告诉我如何解决此问题吗?我也面临同样的问题,请告诉我您对代码做了哪些更改您能告诉我解决方案吗?