UICollectionView Assertion failure

前端 未结 14 2200
别那么骄傲
别那么骄傲 2020-11-29 17:27

I m getting this error on performing insertItemsAtIndexPaths in UICollectionView

Assertion failure in:

-[UICollectionViewD         


        
14条回答
  •  温柔的废话
    2020-11-29 18:15

    Inserting section#0 just before inserting cells seems make UICollectionView happy.

    NSArray *indexPaths = /* indexPaths of the cells to be inserted */
    NSUInteger countBeforeInsert = _cells.count;
    dispatch_block_t updates = ^{
        if (countBeforeInsert < 1) {
            [self.collectionView insertSections:[NSIndexSet indexSetWithIndex:0]];
        }
        [self.collectionView insertItemsAtIndexPaths:indexPaths];
    };
    [self.collectionView performBatchUpdates:updates completion:nil];
    

提交回复
热议问题