Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.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
Ios 快速双点击识别器响应单点击识别器_Ios_Swift - Fatal编程技术网

Ios 快速双点击识别器响应单点击识别器

Ios 快速双点击识别器响应单点击识别器,ios,swift,Ios,Swift,我的应用程序有一个奇怪的问题;当我向标签添加单点击识别器时,它工作正常: private func addDoubleTabGestureRecognizerToWordLabel(){ wordLabel.isUserInteractionEnabled = true let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(labelClicked(gesture:)

我的应用程序有一个奇怪的问题;当我向标签添加单点击识别器时,它工作正常:

private func addDoubleTabGestureRecognizerToWordLabel(){
    wordLabel.isUserInteractionEnabled = true
    
    let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(labelClicked(gesture:)))
    
    
    wordLabel.addGestureRecognizer(gestureRecognizer)
    
    
}

但当我把水龙头号码改成其他类似的号码时

private func addDoubleTabGestureRecognizerToWordLabel(){
    wordLabel.isUserInteractionEnabled = true
    
    let gestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(labelClicked(gesture:)))
    
    
    gestureRecognizer.numberOfTapsRequired = 2
    
    
    wordLabel.addGestureRecognizer(gestureRecognizer)
    
    
}
点击标签时出现以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[PolyLibrum.WordLabel showInfoAroundWordLabelWhenTabbed:]: unrecognized selector sent to instance 0x7fdea951b2d0'
更奇怪的是,当我点击标签一次而不是两次时,就会触发错误

以下是选择器功能:

@objc func labelClicked(gesture: UITapGestureRecognizer) {
    print("UILabel clicked")
    
    
    //executed when the label is double tapped
    //worked when I set the gestureRecognizer.numberOfTapsRequired = 1
    
    let bubbleFrame = wordLabel.frame;
    let translationBubble = TranslationBubble(frame: bubbleFrame)
    
    wordFrame.addSubview(translationBubble as! UIImageView)
}
为什么识别器在单次点击而不是双击时被触发?选择器功能与触发它所需的点击次数有什么关系


感谢您的帮助。

这可能是由于管理不善,无法为该识别器添加点击手势。您可能不需要将手势发送到选择器功能

改变这个

让gestureRecognizer=UITapGestureRecognizer(目标:自我,操作:#选择器(labelClicked(手势:))

让gestureRecognizer=UITapGestureRecognizer(目标:自我,操作:#选择器(labelClicked))
中添加DoubleTabgestureRecognitizerToOrdLabel()

并删除
labelClicked()
中的接收参数


希望这有帮助

事实证明,正如Sweeper在评论中所说的那样,我忘了删除我之前正在试验的interface builder手势识别器。当我移除元素时,一切都正常。再次感谢您的回答。

在项目中搜索“showInfoAroundWordLabelWhenTabbed”一词,尤其是在故事板/XIB文件中。当你不知道标签不存在时,可能有什么东西触发了选择器。非常感谢你的回答。不幸的是,它没有解决问题,但它确实清理了我的代码很多。“姿态”的论点确实是多余的。非常感谢。
@objc func labelClicked(gesture: UITapGestureRecognizer) {
    print("UILabel clicked")
    
    
    //executed when the label is double tapped
    //worked when I set the gestureRecognizer.numberOfTapsRequired = 1
    
    let bubbleFrame = wordLabel.frame;
    let translationBubble = TranslationBubble(frame: bubbleFrame)
    
    wordFrame.addSubview(translationBubble as! UIImageView)
}