- (void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath {
if(editingStyle == UITableViewCellEditingStyleDelete) {
//Get the object to delete from the array.
NSLog(@"%@",[[_arrayForTable valueForKey:@"IDS"] objectAtIndex:[indexPath row]] );
NSInteger myInteger = [[[_arrayForTable valueForKey:@"IDS"] objectAtIndex:[indexPath row]] integerValue];
NSNumber *selRow = [NSNumber numberWithInt:myInteger];
NSLog(@"%@",selRow);
[self removeCell:selRow]; // this is working perfectly it gets remove from database
//Delete the object from the table.
// app get crash here crash report is pested below
[self.table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
- (void) removeCell:(NSNumber *)selRow{
NSLog(@"_arrayForTable%@",_arrayForTable);
NSInteger myInteger = [selRow integerValue];
[_arrayForTable removeObjectAtIndex:myInteger];
NSLog(@"_arrayForTable%@",_arrayForTable);
if(deleteStmt == nil) {
const char *sql = "delete from PersonNamesAndBirthDates where ID = ?";
NSLog(@"%s",sql);
if(sqlite3_prepare_v2(database1, sql, -1, &deleteStmt, NULL) != SQLITE_OK)
NSAssert1(0, @"Error while creating delete statement. '%s'", sqlite3_errmsg(database1));
}
NSLog(@"%d",myInteger);
//When binding parameters, index starts from 1 and not zero.
sqlite3_bind_int(deleteStmt, 1, myInteger );
if (SQLITE_DONE != sqlite3_step(deleteStmt))
NSAssert1(0, @"Error while deleting. '%s'", sqlite3_errmsg(database1));
sqlite3_reset(deleteStmt);
}
* Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableView.m:1046 2013-04-08 17:01:13.069 birthdate reminder 2[583:15803] * 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 (12) must be equal to the number of rows contained in that section before the update (12), 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).'
please suggest something
my numberofrow method is below
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return _arrayForTable.count;
}
app is not crashing everytime sometime works sometime crash
removeCell:
, that it is working perfectly, might be the problem. The row might be deleted from your database, but have you checked your variable_arrayForTable
? It seems, it's still in there. – fguchelaar