从UITableViewCell隐藏删除按钮

mea*_*ers 1 uitableview ios

  • 当我的表格视图处于编辑模式时,会出现红色( - )按钮.
  • 当用户点击其中一个时,会出现[删除]按钮.
  • 当用户点击[删除]时,我首先检查一些事情(部分在线).可能不允许删除此删除.

  • 当不允许删除该单元格时,如何隐藏[删除]按钮并以动画方式再次将红色(|)按钮变为( - )?所以,我不希望我的整个表离开编辑状态.

sps*_*ley 7

我自己遇到了这个问题,我可能会提出一个警报视图来进一步提示用户,如果他们选择不继续,则希望重置删除按钮.这似乎是最简单的方法,假设deleteIndexPath是选择删除的行的索引路径:

[self.tableView reloadRowsAtIndexPaths:@[deleteIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
Run Code Online (Sandbox Code Playgroud)

  • 这是OP问题的正确答案 - 更好的例子是用户点击删除,程序生成actionSheet确认,用户取消.使用UITableViewRowAnimationRight也更好,因为当出现删除按钮时,这与运动相反. (3认同)

ric*_*350 7

要获得实际的动画(而不是UITableViewRowAnimationRight/ UITableViewRowAnimationAutomatic)动画,只需这样做

[self.tableView beginUpdates];
[self.tableView setEditing:NO animated:NO];
[self.tableView setEditing:YES animated:NO];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)

beginUpdatesendUpdates提供动画,tableView刚刚从编辑切换到编辑,关闭删除按钮.

希望这可以帮助!

  • 这个答案是不正确的,但是因为你建议使用`setEditing`我把它选为''答案'.答案应该是:`[self.tableView setEditing:NO animated:YES];`; 是的,就是这样.不知道为什么你将`animated`设置为`NO`,为什么你再次将表设置回编辑模式,并且不需要`begin/endUpdates`来获取动画[Apple文档](https://开发人员. apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/#//apple_ref/occ/instm/UITableView/setEditing:animated :)解释. (5认同)