下面的代码正确显示了我的标题视图,但是对于 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”的标题视图,而是返回“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;
}
}
我需要做什么才能仅显示某些部分的标题视图?