viewForSupplementaryElementOfKind からこの「空の配列の境界を超えたインデックス 0」エラーが発生することがあります。通常、コレクションは正常にロードされ、すべてがスムーズに実行されます。どの配列が空なのだろうか?登録された細胞?(コードまたはインターフェイスビルダーから登録しようとしましたが、まだ変更されていません)
コレクションの読み込みの早い段階でこのメソッドが呼び出され、まだ読み込まれていないデータが不足している場合があると推測しています。
誰かが私を任意の方向に向けることができますか?
私の実装は非常に簡単です:(そして、ビューで適切な再利用識別子を使用しました)
- (UICollectionReusableView *)collectionView:(UICollectionView *)theCollectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)theIndexPath{
UICollectionReusableView *theView;
if(kind == UICollectionElementKindSectionHeader)
{
theView = [theCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:theIndexPath];
} else {
theView = [theCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:theIndexPath];
}
return theView;}