以下のコードは、ヘッダー ビューを正しく表示しますが、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;
}
}
特定のセクションのみのヘッダー ビューを表示するには、どうすればよいですか?