每当我点击DeleteRows代码时,都会得到一个异常,告诉我更新前后的行数需要相同。以下是官方文本:在TableView中删除行时出现异常
原因:无效更新:节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);
}
}
我能够从你所说的我能够实现我的DeleteRows和RemoveAt在错误的顺序。一旦我改变了他们的订单,那很好。谢谢! –