Erro de falha de declaração ao tentar excluir uma linha de um UITableView
-
13-12-2019 - |
Pergunta
Às vezes recebo este erro ao tentar excluir uma linha do UITableView:
Falha de declaração em -[UITableView _endCellAnimationsWithContext:]
e outras vezes exclui a linha sem problemas.
Aqui está o meu código:
- (void) tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
[[self displayedObjects] removeObjectAtIndex:[indexPath row]];
// Animate deletion
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[[self tableView] deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
}
}
Solução
Parece que o seu númeroOfRowsInSection às vezes retorna o número inteiro errado quando você entra no modo de edição.
Outras dicas
Não tão certo..mas tente isso (funcionou para mim uma vez)
Primeiro anime a exclusão do UITableView e, em seguida, remova o objeto do array.
if (editingStyle == UITableViewCellEditingStyleDelete)
{
// Animate deletion
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
[[self tableView] deleteRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationFade];
[[self displayedObjects] removeObjectAtIndex:[indexPath row]];
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow