質問

私は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);
        }
    }
役に立ちましたか?

解決

おそらく

で返される番号を変更する必要があります
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section

indexPath.sectionが削除前より1低くするためます。

ここで答えたとおりのUITableViewはにクラッシュから行を削除

他のヒント

私はそれが私のために働いたことは削除しました tableView.DeleteRows(新しい[] {} 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();
        }
    }
scroll top