每当我点击 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);
}
}