tableView滑动删除以及滑动删除崩溃的原因



1.滑动删除的几个相关的方法
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{//tabble的行可以编辑

    if(indexPath.row == [mArr_dataScore count]){

        return NO;

        //最后一行不能编辑。

    }else{

        return YES;

    }

}



-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

{//进入编辑状态

    if(indexPath.row != [mArr_dataScore count]){

        if (editingStyle == UITableViewCellEditingStyleDelete) {

            [VideoClient clearUserInfo];

            Member * ber = [mArr_dataScore objectAtIndex:indexPath.row];

            [VideoClient removeUserWithUsername:ber.str_tittle];

            [mArr_dataScore removeObjectAtIndex:indexPath.row];

            [tableView reloadData];

        }

    }

    

}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath

{

    return @"删除";


}



UItabview 上面三个方法调用里没有。。。试试看呗。。。

2.滑动删除崩溃
2015-03-17 10:35:56.937 ToDoList[1287:63676] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3318.93/UITableView.m:1582
2015-03-17 10:35:56.941 ToDoList[1287:63676] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.  The number of rows contained in an existing section after the update (3) must be equal to the number of rows contained in that section before the update (3), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

崩溃的原因:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath

此方法中删除数据的顺序有误,正确的顺序“数据库——table所加载的数组——数据对应的cell”


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值