2

DeleteRowsコードをヒットするたびに、更新の前後の行数を同じにする必要があるという例外が発生します。公式テキストは次のとおりです。

理由:無効な更新:セクション0の行数が無効です。更新後の既存のセクションに含まれる行数(3)は、更新前のそのセクションに含まれる行数(3)にプラスまたはマイナスで等しくなければなりません。そのセクションから挿入または削除された行の数(0が挿入され、1が削除されました)。

私のコードは次のとおりです。

        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);
        }
    }
4

2 に答える 2

1

おそらく、返される数を変更する必要があります

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

削除前よりindexPath.sectionも1つ低くなります。

ここで答えたように:uitableviewのクラッシュから行を削除する

于 2010-02-11T17:44:10.073 に答える
0

私にとってうまくいったのは、tableView.DeleteRows(new [] {indexPath}、UITableViewRowAnimation.Fade);を削除することでした。メソッドは次のようになります。

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();
        }
    }
于 2018-02-13T13:04:34.103 に答える