を使用してUICollectionView
、別の を追加しようとしていUICollectionViewCell
ます。この最初のコードは最初のセルを示しており、正常に実行されます。別の を追加しようとすると、問題が発生しUICollectionViewCell
ます。
static NSString *identifier = @"Cell"; // Default Cells
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *illustrationImage = (UIImageView *)[cell viewWithTag:100];
illustrationImage.image = [UIImage imageNamed:[stackImage objectAtIndex:indexPath.row]];
UILabel *stackLabel = (UILabel *)[cell viewWithTag:12];
[stackLabel setText:[stackTitle objectAtIndex:indexPath.row]];
そして、ここで、コンテンツが異なるまったく新しいセルを my に追加したいと思いUICollectionView
ます。このコードを実行するたびに、全体が起動を拒否します:
static NSString *newIdentifier = @"AddNewCell";
UICollectionViewCell *newCell = [collectionView dequeueReusableCellWithReuseIdentifier:newIdentifier forIndexPath:indexPath];
UIImageView *addNewImage = (UIImageView *)[newCell viewWithTag:120];
addNewImage.image = [UIImage imageNamed:[addNew objectAtIndex:indexPath.row]]; // This line makes the app crash
return cell;
return newCell;
エラーメッセージ
キャッチされていない例外 'NSRangeException' が原因でアプリを終了しています。理由: ' * -[__NSArrayI objectAtIndex:]: 境界を超えたインデックス 1 [0 .. 0]'
これは と関係があると思いますindexPath.row
。次のコードのセクションを「0」に置き換えると、indexPath.row
クラッシュはしませんが、UICollectionView
.
[addNew objectAtIndex:indexPath.row]]