Pergunta

Sempre que atingi o código Deleterows, recebo uma exceção dizendo que o número de linhas antes e depois da atualização precisa ser o mesmo. Aqui está o texto oficial:

Motivo: Atualização inválida: Número inválido de linhas na seção 0. O número de linhas contidas em uma seção existente após a atualização (3) deve ser igual ao número de linhas contidas nessa seção antes da atualização (3), mais ou menos O número de linhas inseridas ou excluídas dessa seção (0 inserido, 1 excluído).

Meu código é:

        public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
    {
        if (editingStyle == UITableViewCellEditingStyle.Delete)
        {
            tableView.DeleteRows(new [] { indexPath }, UITableViewRowAnimation.Fade);
    // Remove the step from the set of calculations
    _calculation.Steps.RemoveAt(indexPath.Row);
        }
    }
Foi útil?

Solução

Você provavelmente precisa alterar o número retornado em

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section

para o indexPath.section ser um menor do que antes da exclusão.

Conforme respondido aqui: Exclua linha de travas de uabableView

Outras dicas

O que eu achei que funcionava para mim foi remover a tabelaview.deleterows (new [] {indexPath}, uitableViewRowanimation.fade); Seu método deve parecer algo assim.

public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
    {
        if (editingStyle == UITableViewCellEditingStyle.Delete)
        {
          // Remove the step from the set of calculations
           _calculation.Steps.RemoveAt(indexPath.Row);
           tableView.reloadData();
        }
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top