我有一个包含一些自定义单元格的UITableView。在这些自定义单元格中,我定义了一个触发该表的编辑模式的UILongPressGestureRecognizer。因此,当有人按住单元格1.5秒时,表格就会进入编辑模式。
UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(startEditMode:)];哪种触发方式:
- (void)startEditMode:(UISwipeGestureRecognizer *)recognizer {
if (self.allowEdit) {
UITableView *table = (UITableView *)self.superview;
[table setEditing:YES animated:YES];
}
}但我想要做的是检测表格何时进入编辑模式,因为在这种情况下,我需要显示/隐藏一些额外的按钮。但由于某种原因,在我的视图控制器中,这永远不会被执行:
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
NSLog(@"SET EDITING");
[super setEditing:editing animated:animated];
}有什么建议吗?这是否只是在使用UINavigationController中默认提供的正确编辑按钮时才调用的?
或者如何检测UITableView何时进入编辑模式?
发布于 2012-02-05 22:30:06
您正在将消息(setEditing)发送到表视图,您应该将其发送到视图控制器(假设是UITableViewController子类?)。然后,它将为您处理表视图。
发布于 2012-02-05 23:52:32
好的,如果其他人遇到同样的问题,我将向你展示我是如何解决这个问题的。
在我的自定义UITableViewCell中,我现在有了这个方法:
- (void)startEditMode:(UISwipeGestureRecognizer *)recognizer {
if (self.allowEdit) {
UITableView *table = (UITableView *)self.superview;
UITableViewController *control = (UITableViewController *)table.dataSource;
[control setEditing:YES animated:YES];
}
}https://stackoverflow.com/questions/9149887
复制相似问题