How to change the UICollectionView footerview's height programatically

前端 未结 1 1040
感情败类
感情败类 2020-12-17 04:42

I run into an issue that in my UICollectionView, I need to display a footer when the record returned is 0. The codes below seems working good, when there is no record, foote

相关标签:
1条回答
  • 2020-12-17 04:58

    Btw, what is your self.view.frame.size.height? I hope that's definitely not going to be zero in any moment. Because self.view is the top view in the hierarchy inside the view controller.

    You need not to change the footer size in viewForSupplementaryElementOfKind: method. All you have to find is when you shouldn't show your footer in a particular section.

    Try this and let me know if this works for you.

    - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
    {
        BOOL sectionToHide = [self checkIfThisSectionToHide:section]; // find if the section to hide here..
        if (sectionToHide) {
            return CGSizeZero;
        }else {
            return CGSizeMake(320, self.view.frame.size.height);
        }
    }
    
    0 讨论(0)
提交回复
热议问题