私のアプリはUICollectionView
、カード マッチング ゲームの多数のカスタム サブビューを表示する で構成されています。基本的に、3 枚のカードが一致すると、それらを含むセルがコレクション ビューから削除されます。私の削除機能は、スクロール可能な画面に 3 つのセルすべてが表示されている場合は機能しますが、1 つまたは 2 つが画面外にある場合は機能しません。何が起こるかというと、画面上のセルは削除されますが、他のセル (同様に削除されるはずです) を上にスクロールしようとすると、アプリがクラッシュします。
以下は、私のカード更新機能のコードです。
- (void) updateCell: (SetCardCell*) cell withCard: (SetsCard *) cardInModel {
if ([cell isKindOfClass: [SetCardCell class]]){
if ([cell.setCardView isKindOfClass:[SetCardView class]]) {
// various actions to match view with model
SetCardView *cardView = cell.setCardView;
[cardView setNeedsDisplay];
// do things to UI if card is faced up or unplayable
if (!cardInModel.isUnplayable) {
if (cardInModel.isFaceUp) {
cell.setCardView.alpha = 0.3;
} else {
cell.setCardView.alpha = 1;
}
} else {
// remove the cell - this is where the problem is
NSLog(@"%@", cell.description); ** returns a cell **
NSLog(@"%@", [self.collectionView indexPathForCell:cell].description); ** returns (null) when the cell is offscreen, but a normal index path if otherwise **
[self.game.cards removeObjectsInArray:@[cardInModel]];
[self.collectionView deleteItemsAtIndexPaths:@[[self.collectionView indexPathForCell:cell]]];
}
}
}
}
これを修正する方法についてのアイデアはありますか? どうもありがとうございました!
編集: 以下のようなエラー メッセージが表示されることを忘れていました。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'