使用新的2.2版本的Swift,我无法使用#selector
来调用(相同)扩展中扩展内定义的方法。编译器为doSomething(_:)
说明 unresolved itendifier 。
extension UIViewController {
func doSomething(){
//...
}
func setTapGestureRecognizer(){
let recognizer = UITapGestureRecognizer(target: self, action: #selector(doSomething(_:))) //unresolved itendifier
view.addGestureRecognizer(recognizer )
}
}
我已尝试使用doSomething()
标记方法@objc
但未成功。
答案 0 :(得分:0)
你的func没有输入参数。 将其修复为:
func setTapGestureRecognizer(){
let recognizer = UITapGestureRecognizer(target: self, action: #selector(doSomething))
view.addGestureRecognizer(recognizer)
}