iphone - 如何在 iPhone UITableView 上检测编辑模式

标签 iphone ios cocoa-touch

对于我的 iPhone 应用程序,我有一个可编辑(用于删除)的 TableView 。我希望能够检测到用户单击了“编辑”按钮。看到这张图片:http://grab.by/It0

从文档来看,如果我实现了:

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

然后我就可以检测到它(尽管从方法的名称来看,我不这么认为)。这被证明是行不通的。

关于检测这个有什么想法吗?我想要这样做的原因是我想在删除模式下在左上角连接一个“全部删除”按钮。

谢谢

最佳答案

它可能没有像您预期的那样工作,因为willBeginEditingRowAtIndexPath: 在编辑开始之前被调用。

如果你想在另一个方法中检查你需要 editing 属性:

@property(nonatomic, getter=isEditing) BOOL editing

如果您想在按下“编辑”按钮时执行某些操作,则需要实现 setEditing 方法:

 - (void)setEditing:(BOOL)editing animated:(BOOL)animated

您可以在 UIViewController 中找到它。 (嗯,这是最有可能的地方;还有其他地方。)

swift 相应地使用以下代码:

open var isEditing: Bool // default is NO. setting is not animated.

open func setEditing(_ editing: Bool, animated: Bool)

关于iphone - 如何在 iPhone UITableView 上检测编辑模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1776045/

相关文章:

ios - 由于 iOS 9.2.1 黑屏,应用在应用商店被拒绝

objective-c - 滚动到底部时向 UITableView 添加行

iphone - 在 iPhone 应用程序中播放连续声音

iphone - key 扣证书

ios - UISlider和UILabel导致无限循环

ios - 在模拟器上旋转 iPhone 时出现 UICollectionViewCell 大小调整问题

ios - NSMutableArray 追加 NSMutableArray

iphone - 在 UILabel 中显示表情符号?

ios - 什么会阻止我的用户接收短信?

javascript - 在 iPad 上调试 trigger.io 应用程序