gpt4 book ai didi

ios - 使用 iOS UICollectionView 仅允许某些部分的标题 View

转载 作者:IT王子 更新时间:2023-10-29 07:49:42 24 4
gpt4 key购买 nike

下面的代码正确显示了我的标题 View ,但对于 UICollectionView 中的每个部分:

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath {
UICollectionReusableView * headerView =
[collectionView
dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:@"SectionHeaderCollectionReusableView"
forIndexPath:indexPath];
switch (indexPath.section) {
case Section_One:
return headerView;
case Section_Two:
return headerView;
case Section_Three:
return headerView;
case Section_Four:
return headerView;
case Section_Five:
return headerView;

default:
return headerView;
}
}

我想做的不是显示“Section_One”或“Section_Two”的标题 View ,而是返回“nil”导致“NSInternalInconsistencyException”:

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath {
UICollectionReusableView * headerView =
[collectionView
dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader
withReuseIdentifier:@"SectionHeaderCollectionReusableView"
forIndexPath:indexPath];
switch (indexPath.section) {
case Section_One:
return nil;
case Section_Two:
return nil;
case Section_Three:
return headerView;
case Section_Four:
return headerView;
case Section_Five:
return headerView;

default:
return nil;
}
}

我需要做什么才能只显示某些部分的标题 View ?

最佳答案

继续为每个部分返回一个标题,然后在此 UICollectionViewDelegate 函数中将部分标题的大小设置为零。

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return CGSizeZero;
}else {
return CGSizeMake(self.collectionView.bounds.size.width, desiredHeight);
}
}

关于ios - 使用 iOS UICollectionView 仅允许某些部分的标题 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23900862/

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