views:

173

answers:

1

Whenever I hit the DeleteRows code, I get an exception telling me that the number of rows before and after the update need to be the same. Here's the official text:

Reason: Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).

My code is:

        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);
        }
    }
+1  A: 

You probably need to change the number returned in

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

for the indexPath.section to be one lower than before the deletion.

As answered here: http://stackoverflow.com/questions/2229626/delete-row-from-uitableview-crashes

Felix
I was able to realize from what you said that I was doing my DeleteRows and RemoveAt in the wrong order. Once I switched their order, it was fine. Thanks!
Driss Zouak