Ios UILongPressGestureRecognitor在UITextField上不工作

Ios UILongPressGestureRecognitor在UITextField上不工作,ios,uitextfield,uigesturerecognizer,Ios,Uitextfield,Uigesturerecognizer,我在viewcontroller的viewDidLoad方法中初始化了LongPress手势识别器,如下所示: longPressGesture_= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(displayTimeFlagCallout)]; 我的viewcontroller中有一个tableview。tableview具有自定义单元格。每个单元格有2个文本字段。我想在用户长按文本字段(

我在viewcontroller的viewDidLoad方法中初始化了LongPress手势识别器,如下所示:

longPressGesture_= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(displayTimeFlagCallout)];
我的viewcontroller中有一个tableview。tableview具有自定义单元格。每个单元格有2个文本字段。我想在用户长按文本字段(startTime和endTime)时打开一个自定义popover。我不希望放大镜和复制/粘贴弹出框作为标准行为显示在文本字段的长按上,因此在添加手势识别器之前,我将禁用文本字段的内置长按手势识别器。我已将以下代码添加到cellforRowAtIndexPath方法中:

MyCustomCell_iPhone *cell = [tableView dequeueReusableCellWithIdentifier:cellID];

if (cell == nil)
  {
    cell = [[MyCustomCell_iPhone alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];


      for (UIGestureRecognizer *recognizer in cell.startTime.gestureRecognizers) {
          if ([recognizer isKindOfClass:[UILongPressGestureRecognizer class]]){
              recognizer.enabled = NO;
          }
      }
      for (UIGestureRecognizer *recognizer in cell.endTime.gestureRecognizers) {
          if ([recognizer isKindOfClass:[UILongPressGestureRecognizer class]]){
              recognizer.enabled = NO;
          }
      }

      [cell.startTime addGestureRecognizer:longPressGesture_];
      [cell.endTime addGestureRecognizer:longPressGesture_];


  }
然而,这是行不通的。现在长时间的新闻报道什么也没发生。有什么想法吗?可能是什么问题

谢谢 赫塔尔有三种想法:

  • 不能对两个控件使用相同的长按手势识别器。您必须为每个控件创建单独的手势识别器

  • 当您开始在文本字段中编辑时(假设您允许在文本字段中编辑),手势识别器似乎会重置。我假设您允许编辑文本字段,如果允许,我相信您必须设置一个代理,该代理将禁用非您自己的长手势识别器。(您可以这样做,对于长按手势识别器,将其子类化为,例如
    CustomLongPressGestureRecognizer
    ,将其用于文本字段的手势识别器,然后您可以禁用任何不是您自己的
    CustomLongPressGestureRecognizer
    对象)

  • 我从您的代码推断您没有使用故事板和原型单元,因为在这种情况下,
    cell
    永远不会
    nil
    ,并且您的
    if
    语句永远不会调用您的代码。但是,如果您使用NIB或不使用原型单元,那么在这一点上您应该没有问题


  • 你能回答我的问题吗?你能回答我的问题吗?