'Atualização inválida: número inválido de linhas na seção 0

Eu li todas as postagens relacionadas sobre isso e ainda estou tendo um erro:

'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (5) must be equal to the number of rows contained in that section before the update (5), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

Aqui estão os detalhes:

no.h eu tenho umNSMutableArray:

@property (strong,nonatomic) NSMutableArray *currentCart;

No.m meunumberOfRowsInSection se parece com isso:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.


    return ([currentCart count]);

}

Para ativar excluir e remover o objeto da matriz:

// Editing of rows is enabled
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {

        //when delete is tapped
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

        [currentCart removeObjectAtIndex:indexPath.row];


    }
}

Eu pensei que, tendo meu número de seções contando com a contagem da matriz que estou editando, garantiria o número adequado de linhas? Isso não pode ser feito sem a necessidade de recarregar a tabela quando você exclui uma linha?

questionAnswers(2)

yourAnswerToTheQuestion