I getting exception, while deleting a row using " commitEditingStyle " method in iPhone simulator.
Posted
by Madan Mohan
on Stack Overflow
See other posts from Stack Overflow
or by Madan Mohan
Published on 2010-04-28T08:27:32Z
Indexed on
2010/04/28
8:33 UTC
Read the original article
Hit count: 511
Hi,
I am getting exception by deleting a row from the table view.
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { if(isEdit == YES) { if([editObject.contactList count]>0) { return [editObject.contactList count]+1; } else { return 1; }
}
else if(isEdit == NO) { if([addContactList count]>0) { return [addContactList count]+1; } else { return 1; } }return 0; }
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1; } -(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { if(isEdit == YES) { int sectionNum=[editObject.contactList count]-1; if([editObject.contactList count]>0) {
for( int i=0; i<=[editObject.contactList count]-1;i++) { if(indexPath.section == i) {
} if(indexPath.section == sectionNum+1) { return UITableViewCellEditingStyleInsert; }return UITableViewCellEditingStyleDelete; }
}
else { if(indexPath.section == 0) { return UITableViewCellEditingStyleInsert; } }} else { if([addContactList count]>0) { int sectionNum=[addContactList count]-1;
for( int i=0; i<=[addContactList count]-1;i++) { if(indexPath.section == i) { return UITableViewCellEditingStyleDelete; } } if(indexPath.section == sectionNum+1) { return UITableViewCellEditingStyleInsert; }
}
else { if(indexPath.section == 0) { return UITableViewCellEditingStyleInsert; } } } return UITableViewCellEditingStyleNone; }(void)tableView:(UITableView *)tv commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if(isEdit == YES) { if(editingStyle == UITableViewCellEditingStyleDelete) { for(int i=0;i<=[editObject.contactList count]-1;i++) { if(indexPath.section == i) { [editObject.contactList removeObjectAtIndex:indexPath.row]; [theTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } } } else { //adding } [theTableView reloadData]; } else { if(editingStyle == UITableViewCellEditingStyleDelete) { for(int i=0;i<=[addContactList count]-1;i++) { if(indexPath.section == i) { [addContactList removeObjectAtIndex:indexPath.row]; [theTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; // getting exception here in this line at indexpath [theTableView reloadData];
} } } else { //adding } [theTableView reloadData];
}
}
the exception as 2010-04-28 13:55:30.063 Zoho[2818:20b] * Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-984.38/UITableView.m:772 2010-04-28 13:55:30.064 Zoho[2818:20b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (3), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).' 2010-04-28 13:55:30.065 Zoho[2818:20b] Stack: ( 10490971, 2437656123, 10574907
© Stack Overflow or respective owner