UILongPressGestureRecognizer不上的UITextField

问题描述:

工作,我有我的视图控制器的viewDidLoad方法初始化为低于长按手势识别:UILongPressGestureRecognizer不上的UITextField

longPressGesture_= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(displayTimeFlagCallout)]; 

我在我的ViewController一个的tableview。 tableview有自定义单元格。每个单元格有2个文本框。我想在用户长按文本字段(startTime和endTime)时调出自定义弹出窗口。我不希望放大镜和复制/粘贴弹出窗口显示在长按文本字段作为标准行为,因此在添加我的手势识别器之前,我正在禁用文本字段的内置长按手势识别器。我已将以下代码添加到我的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_]; 


    } 

但是,这不起作用。长按现在什么都没有发生。任何想法可能是什么问题?

感谢 Hetal

+0

你能给的答案在我的问题吗? http://stackoverflow.com/questions/40277505/manage-long-press-on-uitextfiled-without-disabling-context-menu –

三个想法:

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

  2. 这样看来,手势识别器被重置,当你在文本字段开始编辑(假设你允许编辑的文本字段)。我假设你允许编辑文本字段,如果是这样的话,我相信你必须设置一个代理来禁用不属于你自己的长手势识别器。 (你可以做到这一点,你长按手势识别,子类作为,说CustomLongPressGestureRecognizer,使用你的文本字段的手势识别,然后你可以禁用任何UILongPressGestureRecognizer对象不是自己CustomLongPressGestureRecognizer

  3. 我从你没有使用故事板和原型细胞代码推断,因为在这种情况下,cell是从来没有nil和你if声明永远不会结束调用你的代码。但是如果你使用的是NIB或者不使用原型单元,那么你应该在这一点上很好。

+0

你能回答我的问题吗? http://stackoverflow.com/questions/40277505/manage-long-press-on-uitextfiled-without-disabling-context-menu –