我有一组数据(数据源)与一组地址,我的tableview被设置为从数据源的单元格的数量的两倍,所以我可以风格的奇数单元格为小和清晰(使tableview看起来像单元格被一个小空格分隔)。删除一行时出现问题,我执行以下操作:tableview内部不一致时删除
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView beginUpdates];
if (editingStyle==UITableViewCellEditingStyleDelete) {
[self DeleteAddress:[ListAddress objectAtIndex:indexPath.row/2]];
[ListAddress removeObjectAtIndex: indexPath.row/2];
NSIndexPath *nextIndexPath = [[NSIndexPath alloc] initWithIndex:indexPath.row+1];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nextIndexPath,nil] withRowAnimation:UITableViewRowAnimationRight];
}else if (editingStyle == UITableViewCellEditingStyleInsert){
[self tableView:tableView didSelectRowAtIndexPath:indexPath];
}
[tableView endUpdates];
}
DeleteAddress方法从数据库中删除地址。 当调试器到达[实现代码如下endUpdate]功能得到以下错误:
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1070
NSInternalInconsistencyException
应该有更多的错误你正在得到。最可能的问题是您的代码从表中删除了两行(indexPath和nextIndexPath),但您不会从数据源中删除两行,或者从数据源中删除错误的行。另外,由于“插入”代码不执行任何操作,因此只应将'beginUpdates' /'endUpdates'调用放在“删除”代码的周围。 – rmaddy 2013-03-20 00:09:02
我的数据源没有奇数行的值,因为我创建它们只是出于美学目的,所以我只删除数据源中的行,但删除2个可视行。 – jonathanwiesel 2013-03-20 14:35:20