我正在开发一个项目然后我需要添加一个tapGesture,问题是我无法将self添加为目标,我不断收到此错误:
Cannot convert value of type 'NSObject -> () -> ViewController' to expected argument type 'AnyObject?'
这是我的代码:
我也试过了:
let tap = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
但是我得到了同样的错误
答案 0 :(得分:3)
将该行放在onBackPressed
而不是班级:
viewDidLoad
根据我在您编辑问题时看到的内容,您的override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let tap = UITapGestureRecognizer(target: self, action: "dismissKeyboard")
}
变量超出了范围。