views:

47

answers:

1

Hello, i am trying to delete cell on tableview with sliding finger (like on the recent call) i know i need to implement
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSArray *index = [[NSArray alloc]initWithObjects:indexPath];
[self.tableView deleteRowsAtIndexPaths:index withRowAnimation: UITableViewRowAnimationNone];
}

but when i sliede the finger i got to this function and in the second row i am trying to delete the cell an get error:
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (4) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted).'
can someone help??

+2  A: 

When you call

[self.tableView deleteRowsAtIndexPaths:index withRowAnimation: UITableViewRowAnimationNone];

The table view will try and reload, which in turn calls the delegate method

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

Since you have deleted one row, for the necessary animations to work correctly, the table view requires the number of rows to change by the same amount that you deleted with deleteRowsAtIndexPaths:withRowAnimation:. The error message you gets tries to explain that dependency. It is saying you had 4 rows in the table view, you deleted 1... but when the table view asked you how many rows you had after the deletion, you said 4 again instead of 4-1 = 3 which it expected... It then proceeded to off itself presumably because it did not want to live in a world where the laws of natural numbers could not explain reality.

For example if you are using an NSArray* to populate your tableView, you should be deleting the corresponding objects from the array at the same time as you are calling deleteRowsAtIndexPaths:withRowAnimation:.

Akusete