Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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 UILongPressGestiureReconizer标签?-苹果手机_Iphone_Objective C_Ios_Uibutton_Uigesturerecognizer - Fatal编程技术网

Iphone UILongPressGestiureReconizer标签?-苹果手机

Iphone UILongPressGestiureReconizer标签?-苹果手机,iphone,objective-c,ios,uibutton,uigesturerecognizer,Iphone,Objective C,Ios,Uibutton,Uigesturerecognizer,我正在像这样设置一个LPGR,我想知道是否可以在每个LPGR中创建一个标记。我需要这样做,这样我就知道我所有的按钮都被按下了 UILongPressGestureRecognizer *longpressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)]; longpressGesture.minimumPressDuration = 2;

我正在像这样设置一个LPGR,我想知道是否可以在每个LPGR中创建一个标记。我需要这样做,这样我就知道我所有的按钮都被按下了

UILongPressGestureRecognizer *longpressGesture = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressHandler:)];
longpressGesture.minimumPressDuration = 2;
[longpressGesture setDelegate:self];
[pushButton addGestureRecognizer:longpressGesture];
下面是我的方法

- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer {
NSLog(@"longPressHandler");
}
我知道您不能通过选择器传递参数,所以我想知道是否可以为LPGR分配一个标记,或者在方法中是否可以获取使用LPGR的按钮的标记?这有可能吗>

编辑:


您只需创建一个子类
uilongpressurerecognizer
,并向其添加一个
tag
属性。您还可以使用添加带有类别的属性。

UIgestureRecognitor
有一个属性
视图
,该视图是手势识别器附加到的视图

因此,在处理程序方法中,
gesturecognizer.view
是LPGR附加到的按钮,
gesturecognizer.view.tag
是按钮的标记

添加: 示例代码:

- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer {
    NSLog(@"longPressHandler");
    NSInteger tag = gestureRecognizer.view.tag;
    NSLog(@"%d longPressHandler",tag);
}

代码中有几个语法错误:
tag
是属性,因此没有方括号,
NSInteger
是标量类型,而不是对象。我已经在我的答案中添加了正确的代码。
- (void)longPressHandler:(UILongPressGestureRecognizer *)gestureRecognizer {
    NSLog(@"longPressHandler");
    NSInteger tag = gestureRecognizer.view.tag;
    NSLog(@"%d longPressHandler",tag);
}