简体   繁体   中英

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. 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.

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. 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.). 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];


}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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