0
UICollectionView에서 셀을 삭제하려고하면 어설 션 오류가 계속 발생합니다. 내가 카드 게임을하고 있고 카드가 일치하면 삭제 될 것입니다. 일치 할 때 모델에서 일치하는 모든 카드를 삭제 한 다음 CollectionView에서 삭제합니다. 이것은 스탠포드 cs193p 과정에서 배정 # 3의 일부입니다. 여기 내 코드가있다.삭제할 때 UICollectionView에서 어설 션 오류 발생
컨트롤러 코드
-(void) updateUI{
NSMutableArray* tempCardToDelete = [[NSMutableArray alloc] init];
for(UICollectionViewCell *cell in [self.cardCollectionView visibleCells]){
NSIndexPath *indexPath = [self.cardCollectionView indexPathForCell:cell];
NSLog(@"%d", indexPath.item);
Card* card = [self.game cardAtIndex:indexPath.item];
NSLog(@"Face up is %d", card.faceUp);
NSLog(@"%@", card.contents);
// This will update the individual cell with a card value
[self updateCell:cell usingCard:card];
//cards that are not playable and faceup have been matched so we store them
if(card.isFaceUp && card.isUnplayable){
[tempCardToDelete addObject:indexPath];
self.cardsToDelete = [tempCardToDelete copy];
}
}
//delete the cards from the model
[self.game deleteMatchedCards];
//delete the cards from the collectionView
if(self.cardsToDelete.count != 0){
[self.cardCollectionView deleteItemsAtIndexPaths:self.cardsToDelete];
}
}
모델 코드
-(void) deleteMatchedCards{
//the property stores the cards that should be deleted
for(Card *cards in self.modelCardsToDelete){
NSUInteger deleteIndex = [self.modelCardsToDelete indexOfObject:cards];
[self.cards removeObjectAtIndex:deleteIndex];
}
}
modelCardsToDelete가 무엇이라고 정의를? cardsToDelete와 똑같은가? – davis
전체 오류는 무엇입니까? – rmaddy
코드에서 '단언'의 어설 션 오류가 있습니까? (그렇다면 어디에서 나타 납니까?) –