0

hii every one

i am using following code to delete a row in the rgouped table view

- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath {

    if(editingStyle == UITableViewCellEditingStyleDelete) {

        //Get the object to delete from the array.
        insertUpdateDelete *objInsertUpdateDelete = [appDelegate.arrObjects objectAtIndex:indexPath.row];
        [appDelegate DeleteRecord:objInsertUpdateDelete];

        //Delete the object from the table.
        [tableView1 deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}


    }

but its crashing at the line

[tableView1 deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];

crash log is:

2011-05-20 19:21:20.233 iICS[10744:207] * Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1448.89/UITableView.m:995 2011-05-20 19:21:20.235 iICS[10744:207]

 *** 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 (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).'

can any buddy help me? thanx in advance

Bastardo
  • 4,144
  • 9
  • 41
  • 60
Ravi
  • 1,759
  • 5
  • 20
  • 38

3 Answers3

1

Make sure that your data source is reflecting the changes you are making before calling deleteRowsAtIndexPaths:. I see that you are calling [appDelegate DeleteRecord:objInsertUpdateDelete]; but if your data source is not getting its records directly from the appDelegate and getting them from maybe an array in your class you also need to remove it from that array.

As a side note your design pattern for using the app delegate may be like a "ball of mud". Is it good practice to use AppDelegate for data manipulation and Handling?

Community
  • 1
  • 1
Joe
  • 56,979
  • 9
  • 128
  • 135
0

You need to first check if the row you're deleting is the only row in a section.

onnoweb
  • 3,038
  • 22
  • 29
  • no actually i need to delete all the first row in each of the section ,,because the data which i am loading into each rows of the section is coming from a single row of the sqlite database table – Ravi May 20 '11 at 14:15
  • I don't think so. He is starting with 3 rows, and still has 3 rows after the delete. This is happening in section 0, but that's irrelevant. – Rayfleck May 20 '11 at 14:19
0

Look in your method:

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

Does this method always return the correct row count? It seems you're NOT removing the row from whatever datasource is backing your section.

EDIT: It's possible you are doing the delete, but it has not completed (or committed) at the time your table's dataSource is asking for the new rowcount. You might need to delay your [tableView deleteRowsAtIndexPath:] until the database commits.

Rayfleck
  • 12,116
  • 8
  • 48
  • 74