删除时tableview内部不一致 [英] tableview internal inconsistency when deleting

查看:88
本文介绍了删除时tableview内部不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一组地址的数组(数据源),我的tableview被设置为从数据源获得两倍的单元格数量,因此我可以将奇数单元格设置为小而清晰(使tableview看起来像细胞被小空间隔开。删除行时出现问题,我执行以下操作:

I have an array (datasource) with a set of addresses, my tableview is set to have double the amount of cells from the datasource so I can style the odd cells to be small and clear (to make the tableview look like the cells are separated by a small space). My problem comes when deleting a row, I do the following:

-(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方法从数据库中删除地址。
当调试器到达[tableview endUpdate]函数时,得到以下错误:

The DeleteAddress method deletes the address from the database. When the debugger reaches the [tableview endUpdate] function a get the following error:

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2380.17/UITableView.m:1070
NSInternalInconsistencyException


推荐答案

我的问题是我以错误的方式创建了nextIndexPath变量。应该是这样的:

My problem was that I was creating my nextIndexPath variable the wrong way. It should have been like this:

NSIndexPath *nextIndexPath = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];

此外我无法同时删除这两行,我需要从底部单独删除它们:

Also I couldn't delete both rows at the same time, I needed to delete them separately from bottom:

[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:nextIndexPath] withRowAnimation:UITableViewRowAnimationRight];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];

这篇关于删除时tableview内部不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆