简体   繁体   English

当用户未完全滑动以删除表格视图单元格时,如何禁用/启用编辑按钮?

[英]How do i disable/enable edit button when user doesn't fully swipe to delete table view cell?

I have a tableView that allows deletion by swiping a cell or entering edit mode via an "Edit" button. 我有一个tableView,它允许通过滑动单元格或通过“编辑”按钮进入编辑模式来删除。 The problem is, I'm not sure how to properly enable/disable edit mode; 问题是,我不确定如何正确启用/禁用编辑模式。 it should be disabled as soon as a user begins to swipe a row, and enabled after "unswiping" a row. 用户开始滑动行时应将其禁用,并在“取消滑动”行后将其启用。

Currently, I disable in editingStyleForRowAtIndexPath (which returns delete) and enable in didEndEditingRowAtIndexPath. 目前,我在editStyleForRowAtIndexPath中禁用(返回delete),并在didEndEditingRowAtIndexPath中启用。

The problem is, what if the user doesn't finish their swipe? 问题是,如果用户没有完成滑动操作该怎么办? For example, they begin to swipe a row, but release before fully swiping (causing the row to bounce back and hide the delete button). 例如,它们开始滑动一行,但在完全滑动之前释放(导致该行弹回并隐藏“删除”按钮)。 In this case, didEndEditingRowAtIndexPath does not get called. 在这种情况下,didEndEditingRowAtIndexPath不会被调用。 How do I ensure the table is editable after a half-swipe? 半扫后如何确保表格可编辑?

Here you are another approach that work properly,(quit or comment: editingStyleForRowAtIndexPath and didEndEditingRowAtIndexPath.). 这是您可以正常使用的另一种方法(退出或注释:editingStyleForRowAtIndexPath和didEndEditingRowAtIndexPath。)。 And you must implement only this: 而且,您只能执行以下操作:

 -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete)
{
    // Configure delete action:
    // First remove the delete data from you data source.
  Put here you code, like this:
  [self.theMutableArrayWithDataSourde removeObjectAtIndex:indexPath.row];
    // Second remove the cell:
  [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];


}
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM