写完大致的逻辑之后,运行出现:
*** Assertion failure in -[UITableView_endCellAnimationsWithCon
libc++abi.dylib: handler threw exception
报错,因为是删除section里的最后一个单元格。
一般情况下:
1.在调用deleteRowsAtIndexPaths:方法前,要确保数据为最新。也就是说,先将要删除的数据从数据源中删除。
2.分组和分组中行数是变动的,不能写成死的!
3.如果是分组,你会发现很怪的现象:当一个分组中,有多条数据时,你删除其中一条,正确;当一个分组中,你要删除唯一的一条时,仍然会报出如上的错误!
解决如下:
[tableView beginUpdates];
if (tableView == self.tableView) {
if (indexPath.row<[[self.allNameListArray objectAtIndex:indexPath.section] count]) {
int new = [[self.allNameListArray objectAtIndex:indexPath.section] count];
[self.allMembers removeObject:[[self.allNameListArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
[self getIndexTitleArray:self.allMembers isSearch:NO];
if (new ==1 ) {
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
}else{
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];//移除tableView中的数据
}
[tableView endUpdates];
完美解决崩溃----
解决如下:
[tableView beginUpdates];
if (tableView == self.tableView) {
if (indexPath.row<[[self.allNameListArray objectAtIndex:indexPath.section] count]) {
int new = [[self.allNameListArray objectAtIndex:indexPath.section] count];
[self.allMembers removeObject:[[self.allNameListArray objectAtIndex:indexPath.section] objectAtIndex:indexPath.row]];
[self getIndexTitleArray:self.allMembers isSearch:NO];
if (new ==1 ) {
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationFade];
}else{
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];//移除tableView中的数据
}
[tableView endUpdates];
完美解决崩溃----