对象扩展内的#selector - 未解析的itendifier

时间:2016-04-21 10:27:48

标签: selector swift2.2

使用新的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但未成功。

1 个答案:

答案 0 :(得分:0)

你的func没有输入参数。 将其修复为:

func setTapGestureRecognizer(){
    let recognizer = UITapGestureRecognizer(target: self, action: #selector(doSomething))
    view.addGestureRecognizer(recognizer)
}