didSelectItemAtIndexPath の次の実装を持つ UIViewController があります。
@interface
id section1Item
NSMutableArray *section2Items
NSMutableArray *section3Items
@end
@implementation
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
;
} else if (indexPath.section == 1) {
self.section1Item = [self.section2Items objectAtIndex:indexPath.row];
} else { // indexPath.section == 2
id newSection2Item = [self.section3Items objectAtIndex:indexPath.row];
[self.section2Items addObject:newSection2Item];
[self.section3Items removeObject:newSection2Item];
}
[collectionView reloadData];
}
@end
コードの背後にある考え方は、私の collectionView には静的な数のセクションがあり、セクション 3 のアイテムをタップするとアイテムがセクション 2 に移動し、セクション 2 のアイテムをタップするとセクション 1 のアイテムになるというものです。
ただし、dataStructure (section1Item、section2Items、および section3Items) に変更を加えて reloadData を呼び出すと、UICollectionView セルがすべて消えます。問題のいくつかの症状
- reloadData 呼び出しの後、dataSource メソッドが呼び出されません。numberOfSectionsInCollectionView と collectionView:numberOfItemsInSection の実装にブレークポイントを設定しようとしましたが、ヒットしません。
- RevealApp を使用してデバッグを試みたところ、reloadData 呼び出しの後、すべての UICollectionViewCell の hidden プロパティが「YES」に設定されていることがわかりました。
- UICollectionViewCell#setHidden をオーバーライドして、UIKit フレームワークのどの部分がそれを呼び出しているか (もしあれば) を検出しようとしましたが、やはりブレークポイント トリガーはありませんでした。
ツールの詳細: iOS7 シミュレーターで XCode5-DP6 を使用しています。
更新:私の UICollectionView は、最初のレンダリングですべてのセルを正しく表示します。