Assertion Failure in UICollectionViewData indexPathForItemAtGlobalIndex

后端 未结 8 2050
南旧
南旧 2020-12-15 04:15

I am using performBatchUpdates() to update my collection view, where I am doing a complete refresh, i.e. delete whatever was in it and re-insert everything.

8条回答
  •  既然无缘
    2020-12-15 04:29

    This is the proper workaround to this crash:

    Each of your supplementary views are associated with a certain index path. If you don't have a cell at that index path (initial load, you've deleted the row, etc), return a height of 0 for your supplementary view via your layout's delegate.

    So, for a flow layout, implement UICollectionViewDelegateFlowLayout's

    (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
    

    method (and the corresponding footer method, if you're using footers) with the following logic

    if ( you-have-a-cell-at-the-row-for-this-section )
        return myNormalHeaderSize;
    else return CGSizeMake( 0,0 );
    

    Hope this helps!

提交回复
热议问题