开发者

Wipe a delete button out of table view cell

when pressing a row delete button on a table view, I do some validation, and if the user chooses to cancel the operation it all should rollback. Not only want to keep that row (what is happening), but also make 开发者_如何学编程disappear the delete button leaving only the "-" round button. How can I do that?

once again, thank you.


Assuming you are implementing your validations in tableView:commitEditingStyle:forRowAtIndexPath: method of your UITableViewDatasource protocol object, you should be able to set the editingAccessoryType and editingAccessoryView on the cell.

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

}

If you want, you can wrap the changes in an animation block to animate the change.

Alternatively, you could toggle the editing state of the cell.

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

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜