8

Trying to add a section header to my uicollectionview. When I don't use a section header, collection view loads fine, no problems at all. When I try to use one, I get this error:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView dataSource is not set'

I see other people are having this issue but no fix has been found yet. I create the uicollectionview, cell and section view in storyboard. I am registering the header class and setting the datasource and delegate in the code.

Again, uicollectionview works 100% FINE without trying to use section headers. It appears that having a section header causes the app to try and call the datasource/delegate methods automatically instead of waiting for my programmed call. Why is this?

Code:

[self.collectionView registerClass:[MyCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MyCollectionHeaderView"];
self.collectionView.dataSource = self;
self.collectionView.delegate = self;
Sam
  • 6,961
  • 15
  • 44
  • 63
JimmyJammed
  • 9,308
  • 17
  • 74
  • 140

1 Answers1

-1

I've faced this problem too!

The solution is to change your UICollectionView to a UICollectionViewController.

I don't know exactly why this is happening, but at least headers work now.

Gerrit Post
  • 1,129
  • 12
  • 25