Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何将UILongPressGestureRecognitor添加到UIExtField?_Iphone_Objective C_Ios_Ipad_Uitextfield - Fatal编程技术网

Iphone 如何将UILongPressGestureRecognitor添加到UIExtField?

Iphone 如何将UILongPressGestureRecognitor添加到UIExtField?,iphone,objective-c,ios,ipad,uitextfield,Iphone,Objective C,Ios,Ipad,Uitextfield,我正在尝试将UILongPressGestureRecognitizer添加到第页的一个UITextField中,但当长按UITextField时,它不会调用选择器方法。 我将其添加到UItextField,但当我长按TextField但在字段上显示放大镜时,它不会调用选择器方法 [self.tfCustomerStreet addGestureRecognizer:LongPressgesture]; 但是,如果我将选择器方法添加到视图中,它可以正常工作并调用选择器方法 [[self vie

我正在尝试将
UILongPressGestureRecognitizer
添加到第页的一个UITextField中,但当长按UITextField时,它不会调用选择器方法。 我将其添加到UItextField,但当我长按TextField但在字段上显示放大镜时,它不会调用选择器方法

[self.tfCustomerStreet addGestureRecognizer:LongPressgesture];
但是,如果我将选择器方法添加到视图中,它可以正常工作并调用选择器方法

[[self view] addGestureRecognizer:LongPressgesture];
ViewDidLoad中的初始化代码

UILongPressGestureRecognizer *LongPressgesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(LongPressgesture:)];
    [LongPressgesture setMinimumPressDuration:2.0];


请告诉我如何使用UITextField。

如果您删除
[longpress手势设置minimumpressDuration:2.0]它会工作的。。由于将调用制表符手势开始编辑文本字段。。。或者只是实现这个手势委托功能

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}
向此方法返回YES可确保同时识别


享受:)

谢谢Malek。。它开始删除[LongPress手势设置MinimumPressDuration:2.0];但如果添加您提到的代码,则不起作用。但问题解决了。。谢谢:)不客气。。但是对于第二个步骤,您是否在.h中添加了
UIgestureRecognitizerDelegate
?您还需要设置
LongPress手势.delegate=self
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
    return YES;
}