I'm trying to add supplemental footers into a UICollectionView. It seems like I'm hitting all the proper methods according to Apple's documentation but for some reason the:
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
...isn't getting called at all.
I've subclassed UICollectionReusableView to a class called SmartActionFooterView.
In the ViewController, in the ViewDidLoad method I'm registering and associating views with reuse identifier as such:
[self.collectionView registerClass:[SmartActionFooterView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView"];
And then overriding the UICollectionFlowDelegate method with...
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
referenceSizeForFooterInSection:(NSInteger)section
{
NSLog(@"sizing footer");
return CGSizeMake(300,100);
}
This NSLog is printing out.
I'm then hitting the UICollectionViewDataSource method...
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"Something is happening with the footer...");
SmartActionFooterView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footerView" forIndexPath:indexPath];
footerView.backgroundColor = [UIColor yellowColor];
return footerView;
}
This NSLog however is printing nothing, however I'm at a loss as to why.
I have the constraint of needing to do this all programmatically (no storyboards).
Thanks!
I advice you to debug and check. Debugging is a very powerful tool in any IDE and it helps most of the times.
What I think you have not done is to set the
datasourceanddelegateproperties of yourUICollectionViewobject.So, try: