Ios UILongPressGestureRecognitor在UITextField上不工作
我在viewcontroller的viewDidLoad方法中初始化了LongPress手势识别器,如下所示:Ios UILongPressGestureRecognitor在UITextField上不工作,ios,uitextfield,uigesturerecognizer,Ios,Uitextfield,Uigesturerecognizer,我在viewcontroller的viewDidLoad方法中初始化了LongPress手势识别器,如下所示: longPressGesture_= [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(displayTimeFlagCallout)]; 我的viewcontroller中有一个tableview。tableview具有自定义单元格。每个单元格有2个文本字段。我想在用户长按文本字段(
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或不使用原型单元,那么在这一点上您应该没有问题你能回答我的问题吗?你能回答我的问题吗?