_endCellAnimationsWithContext报错解决

来源:互联网 发布:sql联合主键语句 编辑:程序博客网 时间:2024/05/18 01:39

在删除单元格的时候 可能会报这个错误

解决这个问题 要注意以下几点:

1.

      [_dataArray removeObjectAtIndex:indexPath.row];//1.先删除源数据                        [tableView beginUpdates];//2.必须调用begin和end两个方法                if (_dataArray.count <= 0) {//3.删除每个section中的最后一cell时调用删除section方法            [tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationLeft];        }        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];        [tableView endUpdates];

 

2.这两个方法也很关键 这两个方法返回的数据不能写死。特别注意第一个方法,当删除最后一条时,要返回section的个数为0;(多分组道理相同)

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
    if (_dataArray.count>0) {
        return 1;
    }else{
        return 0;
    }
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataArray.count;
}

0 0
原创粉丝点击