【发布时间】:2013-06-17 01:17:30
【问题描述】:
我的应用程序包含一个 UICollectionView,它显示了许多用于纸牌匹配游戏的自定义子视图。基本上,当三张卡片匹配时,包含它们的单元格将从集合视图中删除。当所有三个单元格都在可滚动屏幕上可见时,我的删除功能起作用,但当一两个单元格不在屏幕上时则不起作用。发生的情况是屏幕上的单元格将被删除,但是当我尝试向上滚动以查看其他单元格(也应该被删除)时,应用程序崩溃了。
下面是我的卡片更新功能的代码:
- (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]'
【问题讨论】:
标签: ios xcode scroll uicollectionview