Ios – Hide Delete button from UITableViewCell

iosuitableview

  • When my table view is in edit mode, the red (-) buttons appear.
  • When the user taps one of them the [Delete] button appears.
  • When the user taps on [Delete] I first check a few things (partly online). This delete may not be allowed.

  • When deleting that cell is not allowed, how do I hide the [Delete] button and let the red (|) button become a (-) again in an animated way? So, I don't want my whole table to leave editing state.

Best Answer

To get the actual animation (Instead of the UITableViewRowAnimationRight/UITableViewRowAnimationAutomatic) animations, just do

[self.tableView beginUpdates];
[self.tableView setEditing:NO animated:NO];
[self.tableView setEditing:YES animated:NO];
[self.tableView endUpdates];

beginUpdates and endUpdates provide the animation, and the tableView is just switched from not editing to editing instantly, which closes the delete button.

Hope this helps!

Related Topic