0

emphasized textreason:

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

*** First throw call stack

I got this error when I'm trying to delete

3 Answers3

1

This error means that when you update the UITableView after the deletion, the array that you are using as your Data Source has not been updated.

In other words:

You have the NSArray dataArray that you are using in cellForRowAtIndexPath in your UITableViewDelegate. You animate the cell to delete the row, but then you never call

[dataArray removeObjectAtIndex:index];

So when the table renders again, the UITableView expects there to be 5 items, but your array still has 6.

julianwyz
  • 3,104
  • 1
  • 29
  • 34
0

your question is unclear , follow these steps

  1. in delegate method commitEditingStyle, delete object from array.
  2. then apply deleterow animation on table with updated array.

i think u r not deleting object from your collection i.e array

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
0

try this code.

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
         [tableDataArray removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
       [self.tableView reloadData];
}
}


- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;

}

For More reference You can visit here

Nilesh Jha
  • 1,626
  • 19
  • 35