4

I get the data from API that divided into pages, I user var hasMoreUsers: Bool to 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 set hasMoreUsers = false and calling self.collectionView.performBatchUpdates to add the data

Here is the error

Got this error at line calling self.collectionView.performBatchUpdates

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

Follow by

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

Look like it need dimension for footer, but I already return CGSizeZero for it and this should be the problem. Really confuse.

sarunw
  • 8,036
  • 11
  • 48
  • 84

2 Answers2

5

Supply a non-zero size, such as CGSizeMake(0.01, 0.01)

This appears to be a bug in UICollectionView. Even though the docs specify that returning a size of (0, 0) will result in no footer being added, this only seems to work when using reloadData. If using performBatchUpdates as you are, it will crash.

Ric Santos
  • 15,419
  • 6
  • 50
  • 75
1

[[_collectionView collectionViewLayout] invalidateLayout];

It solves my problem: hide the footer then animate by performBatchUpdates.

and answer is from Saren Inden

Community
  • 1
  • 1
bluekurk
  • 21
  • 9