删除tableviewcell遇到的问题

写完大致的逻辑之后,运行出现:

*** Assertion failure in -[UITableView_endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:1070

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];

完美解决崩溃----

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值