gpt4 book ai didi

ios - UITapGestureRecognizer : "Unrecognized selector sent to instance"

转载 作者:行者123 更新时间:2023-11-28 12:10:40 25 4
gpt4 key购买 nike

我知道这个问题过去被问过很多次,但几乎所有答案都已过时( objective-c )或者它们似乎对我不起作用。

当我尝试点击我的 View 时出现以下异常:

2018-02-05 12:18:30.162887+0100 Shay[28239:1248348] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 
'-[UIView tabClicked:]: unrecognized selector sent to instance 0x7f88edd02240'

这是我的实现:

//setting up the basic properties and adding Tap gesture
init(view: UIView,index: Int, tabHandler: TabHandler, tabType: TabType) {

....

//TapRecognizerAction
let tap = UITapGestureRecognizer(target: rootView, action: #selector( tabClicked(_:) ))
tap.delegate = self as UIGestureRecognizerDelegate
rootView.addGestureRecognizer(tap)

}

@objc public func tabClicked(_ recognizer: UITapGestureRecognizer){
print("WORKING")

}

非常感谢帮助新手!

最佳答案

tabClicked 应该在 rootView 实现中而不是在 self.view 中

你可以试试

  let tap = UITapGestureRecognizer(target: self , action: #selector(  tabClicked(_:) ))

extension UIView
{

@objc public func tabClicked(_ recognizer: UITapGestureRecognizer){
print("WORKING")

}
}

关于ios - UITapGestureRecognizer : "Unrecognized selector sent to instance",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48621610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com