对于我的iPhone应用程序,我有一个可编辑(用于删除)的表视图。我希望能够检测到用户已经点击了“编辑”按钮。查看此图像:http://grab.by/It0
从文档中看,如果我实现了:
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath然后我可以检测到它(尽管从方法的名称来看,我不会这么认为)。事实证明这是行不通的。
对检测这个有什么想法吗?我想这样做的原因是,在删除模式下,我想在左上角挂上一个“全部删除”按钮。
谢谢
发布于 2009-11-22 01:16:07
它可能没有像您预期的那样工作,因为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)发布于 2012-02-20 01:07:29
当子类化tableviewcontroller时(大多数人大部分时间都会这样做,因为你必须覆盖它的委托方法才能将数据放入其中……)你可以直接重写setEditing:animated:方法来获取编辑状态的变化。
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
NSLog(@"Editing %i", editing);
[super setEditing:editing animated:animated];
}它将状态更改传递给超类,但允许您跳到中间并检测更改,或者根据需要更改它……
发布于 2013-04-05 04:03:16
集合setEditing:animated: examples不适用于我(在iOS 6.1上)检测进入和退出删除确认模式时发生的状态变化。setEditing:animated:似乎只在表格视图进入编辑模式时调用一次,而不是在单元格的状态改变时调用。经过一些调试器的乐趣,我找到了一种检测单元状态变化的方法。
我的用例与你的不同。我只是想在显示“删除”按钮时隐藏标签,这样当“删除”按钮滑入时,其他单元格内容就不会与它重叠。(我使用的是UITableViewCellStyleValue2,左边是蓝色标签,右边是黑色标签。)
(在您的UITableViewCell子类中)
- (void)willTransitionToState:(UITableViewCellStateMask)state {
[super willTransitionToState:state];
if (state & UITableViewCellStateShowingDeleteConfirmationMask) {
// showing delete button
[self.textLabel setAlpha:0.0f]; // <-- I just wanted to hide the label
}
}
- (void)didTransitionToState:(UITableViewCellStateMask)state {
if (!(state & UITableViewCellStateShowingDeleteConfirmationMask)) {
// not showing delete button
[self.textLabel setAlpha:1.0f]; // <-- show the label
}
}https://stackoverflow.com/questions/1776045
复制相似问题