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, footer is displayed. However, there is an issue that when there are records, though footer is hidden, code LINE 1 seems do not have any effect, which means the blank space of footer is still there. Any idea how to get rid of it? i.e change the footer'e height to 0 , or just remove the footer when there is record returned.
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
CGSize footerSize = CGSizeMake(320, self.view.frame.size.height);
return footerSize;
}
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
UICollectionReusableView *reusableview = nil;
if (kind == UICollectionElementKindSectionFooter) {
reusableview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
reusableview.hidden = YES;
if([topicArray count]>0){
reusableview.hidden = YES;
//reusableview.frame = CGRectMake(0, 0, 0, 0);
CGRect newFrame = reusableview.frame;
newFrame.size.height =0;
reusableview.frame = newFrame; // <-------- LINE 1.
}else{
reusableview.hidden = NO;
reusableview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
UIImageView *oopsImgView =[[UIImageView alloc] initWithFrame:CGRectMake(60, 130,200,154)];
UILabel *label=[[UILabel alloc] ....;
label.adjustsFontSizeToFitWidth = YES;
label.textAlignment = NSTextAlignmentCenter;
label.lineBreakMode = NSLineBreakByWordWrapping;
label.numberOfLines = 0;
label.font = [UIFont boldSystemFontOfSize:16.0f];
label.minimumScaleFactor = 10.0f/15.0f;
[reusableview addSubview:label];
}
}
return reusableview;
}