4

在一个表格视图中,我在每个单元格上都有一个UILongPressGestureRecognizer我这样添加的:

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] 
                                          initWithTarget:self 
                                          action:@selector(TableCellLongPressed:)];
longPress.minimumPressDuration = 0.5f;
[cell addGestureRecognizer:longPress];
[longPress release];

现在我确实遇到了以下问题,我希望用户能够重新排列 tableview 中的单元格,所以我有一个按钮可以将 tableView 设置为 EditMode,如下所示:

[self.myTableView setEditing:!self.myTableView.editing animated:YES];

现在,当用户尝试拖动一个单元格并且没有将其拖动足够远时,longPress 会触发他的动作,这对用户来说非常烦人,因为另一个视图被推送。UILongPressGestureRecognizer当 tableView 处于 EditMode 时,如何暂停或禁用?

4

1 回答 1

6

您应该为此方法实现 UIGestureRecognizerDelegate 委托:

手势识别器:应该接收触摸:

在该方法中,检查您是否正在编辑表格,如果是则返回 NO。

蒂姆

于 2012-03-23T08:10:22.007 回答