一意の ReuseIdentifier を持つ複数の UICollectionView を使用すると、このエラーがポップアップするのを見てきました。ViewDidLoad では、各 CollectionView の reuseIdentifier を次のように登録します。
[_collectionView1 registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collectionView1CellIdentifier"];
[_collectionView2 registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"collectionView2CellIdentifier"];
次に、「- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath」に到達したら、collectionView1 のセルを collectionView2 の reuseIdentifier に設定しようとしないか、またはこのエラーが発生します。
これを行わないでください : (または、collectionView2 が間違った識別子を参照し、予期していた識別子を参照する前にフィットをスローします)
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionView1CellIdentifier" forIndexPath:indexPath];
if(collectionView != _collectionView1){
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionView2CellIdentifier" forIndexPath:indexPath];
}
cell.backgroundColor = [UIColor greenColor];
return cell;
これを行います:
UICollectionViewCell *cell;
if(collectionView == _collectionView1){
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionView1CellIdentifier" forIndexPath:indexPath];
}else{
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionView2CellIdentifier" forIndexPath:indexPath];
}
cell.backgroundColor = [UIColor greenColor];
return cell;