Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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,应用程序认为我按了两次按钮_Iphone_Objective C_Uibutton - Fatal编程技术网

iphone,应用程序认为我按了两次按钮

iphone,应用程序认为我按了两次按钮,iphone,objective-c,uibutton,Iphone,Objective C,Uibutton,我上过这样的课 @interface UIGestureHolder : UILongPressGestureRecognizer { int tag; } @property (nonatomic, readwrite) int tag; @end @implementation UIGestureHolder @synthesize tag; @end 然后我将其分配给一个按钮,以便在按住按钮时调用buttonheld函数: UIGestureHolder *longpr

我上过这样的课

@interface UIGestureHolder : UILongPressGestureRecognizer {

    int tag;
}
@property (nonatomic, readwrite) int tag;

@end



@implementation UIGestureHolder
@synthesize tag;
@end
然后我将其分配给一个按钮,以便在按住按钮时调用buttonheld函数:

UIGestureHolder *longpressGesture = [[UIGestureHolder alloc] initWithTarget:self action:@selector(buttonHeld:)];
        longpressGesture.minimumPressDuration = 1.5;

        [longpressGesture setDelegate:self];
        longpressGesture.tag=i;
        [contactButton addGestureRecognizer:longpressGesture];
        [longpressGesture release];
Buttonheld函数:

-(void)buttonHeld:(id)sender
{


    int i = ((UIControl *) sender).tag;

    ......

}
当我按住按钮1.5秒或任何我想要的时间时,运行时告诉我我按住按钮两次,每次1.5秒,为什么?这会导致我以后出现异常


为什么运行时认为我按住按钮两次?

可能按钮也启用了单次点击?按钮行为是点击它一次&发生了什么事,对吗


响应程序
分配给按钮时,您做了什么?尝试禁用它&看看你是否得到相同的…

手势识别器会在状态改变时通知你。将代码更改为:

-(void)buttonHeld:(UILongPressGestureRecognizer*)longPressRecognizer 
 {
    if(longPressRecognizer.state == UIGestureRecognizerStateBegan) 
    {
        int i = ((UIControl *) sender).tag;
        ......
    }
}