Я продолжаю получать отказ от утверждения при попытке удалить ячейки из моего UICollectionView. Что я делаю в карточной игре, и когда карты совпадают, они должны быть удалены. Я сделал это, когда они совпадают. Я удаляю все сопоставленные карты в модели, а затем удаляю их из CollectionView. Это часть задания № 3 от курса stanford cs193p. Вот мой код.Сбой утверждения в UICollectionView при удалении
Controller Код
-(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 определяется как? Предполагается, что он будет таким же, как cardToDelete? – davis
Какова полная ошибка, которую вы получаете? – rmaddy
Является ли отказ утверждения от «assert» в вашем коде? (И если да, то где это появляется) –