为什么带有UITapGestureRecognizer的视图控制器崩溃?

时间:2019-02-12 14:51:20

标签: ios swift

为什么我的应用程序在启动时会崩溃,但没有输入任何代码导致任何事情?

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        let tap: UITapGestureRecognizer = UITapGestureRecognizer (target: self, action: #selector(ViewController.keyvoardDismiss))

        view.addGestureRecognizer(tap)
    }

    @objc func keyvoardDismiss() {
        view.endEditing(true)
    }

}

1 个答案:

答案 0 :(得分:2)

keyvoardDismiss不是类方法,请使用

#selector(keyvoardDismiss)