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”