gpt4 book ai didi

ios UICollectionView 以编程方式删除标题

转载 作者:行者123 更新时间:2023-12-02 01:50:16 24 4
gpt4 key购买 nike

我想要控制 UICollectionView 的标题,因为我需要根据用户生成的事件删除和添加它。

到目前为止我已经尝试过:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{

if(toRemoveHeader){

return CGSizeZero;

}else{

return CGSizeMake(320, 45);

}
}

然后每当生成用户事件时调用[self.collectionView reloadData]。我更愿意在不重新加载数据的情况下完成此操作。有什么想法吗?

最佳答案

如果您使用 Swift,您可以在 UICollectionViewController 子类中这样做:

var hideHeader: Bool = true //or false to not hide the header

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
if hideHeader {
return CGSizeZero //supplementary view will not be displayed if height/width are 0
} else {
return CGSizeMake(30,80) //size of your UICollectionReusableView
}
}

关于ios UICollectionView 以编程方式删除标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22400929/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com