I have added <UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
to my collection view and set up my UICollectionView
as below.
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:headerReuseIdentifier];
I have also added the necessary methods.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section {
return CGSizeMake(self.view.frame.size.width, 44.0f);
}
- (UICollectionReusableView *)supplementaryViewForElementKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath {
NSLog(@"supplementaryViewForElementKind called");
if ([elementKind isEqualToString:UICollectionElementKindSectionHeader]) {
UICollectionReusableView *header = [self.collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:headerReuseIdentifier
forIndexPath:indexPath];
header.backgroundColor = [UIColor redColor];
return header;
}
return nil;
}
However, supplementaryViewForElementKind
never gets called. Any ideas?