我遇到了一个问题,就是在我的UICollectionView中,当返回的记录为0时,我需要显示一个页脚。下面的代码似乎工作得很好,当没有记录时,页脚被显示出来。然而,有一个问题,当有记录时,尽管页脚被隐藏了,但代码LINE 1似乎没有任何效果,这意味着页脚的空白空间仍然存在。有什么办法可以摆脱它吗?即改变页脚的高度为0,或者只有在返回记录时才删除页脚。
- (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;
}