Crash on collectionView.performBatchUpdates when trying to hide footer / header

I get data from the API, which are divided into pages, I am a user var hasMoreUsers: Boolto show / hide the footer cell

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
    if hasMoreUsers {
        return CGSizeMake(collectionView.contentSize.width, 50)
    } else {
        return CGSizeZero
    }
}

The code brake on the last page where I installed hasMoreUsers = falseand calling self.collectionView.performBatchUpdatesto add data

Here is the error

Get this error when calling a string self.collectionView.performBatchUpdates

*** Assertion failure in -[UICollectionViewData layoutAttributesForSupplementaryElementOfKind:atIndexPath:], /SourceCache/UIKit_Sim/UIKit-3347.44/UICollectionViewData.m:884

Follow on

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'no UICollectionViewLayoutAttributes instance for -layoutAttributesForSupplementaryElementOfKind: UICollectionElementKindSectionFooter at path <NSIndexPath: 0xc000000000000016> {length = 2, path = 0 - 0}'

It looks like the footer needs a measurement, but I am already returning CGSizeZerofor it, and that should be the problem. Actually confuse.

+4
source share
2 answers

Set a non-zero size, for example CGSizeMake(0.01, 0.01)

, -, UICollectionView. , docs , (0, 0) , , , reloadData. performBatchUpdates, , .

+5

[[collectionView collectionViewLayout] invalidateLayout];

: , performBatchUpdates.

Saren Inden

+1

All Articles