从表格视图单元格中删除删除按钮

时间:2010-02-25 13:42:20

标签: iphone cocoa-touch uitableview

当在表视图上按行删除按钮时,我会进行一些验证,如果用户选择取消操作,则应该回滚。不仅要保留那一行(发生了什么),而且还要删除删除按钮,只留下“ - ”圆形按钮。我怎么能这样做?

再次,谢谢。

1 个答案:

答案 0 :(得分:0)

假设您正在使用tableView:commitEditingStyle:forRowAtIndexPath:UITableViewDatasource协议对象的方法实现验证,您应该能够在单元格上设置editingAccessoryType和editingAccessoryView。

//After validation fails....
UITableViewCell *aCell;  
aCell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
// validations are done and you need to ignore the delete
if ( aCell.showingDeleteConfirmation ){
    aCell.editingAccessoryView = nil;
    aCell.editingAccessoryType = UITableViewCellAccessoryNone;

}

如果需要,可以将更改包装在动画块中以设置更改动画。

或者,您可以切换单元格的编辑状态。

//After validation fails....
UITableViewCell *aCell;  
aCell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
if ( aCell.showingDeleteConfirmation ){
    aCell.editing = NO;
    aCell.editingAccessoryView = nil;
    aCell.editing = YES;

}
相关问题