无法识别的选择器发送到实例(keyboardDidShow)

时间:2016-10-03 13:50:40

标签: ios swift3 nsnotificationcenter

我试图让键盘通知在我的应用中运行但不知何故我一直遇到这个错误。这是我的代码:

override func viewWillAppear(_ animated: Bool) {

    NotificationCenter.default.addObserver(self, selector: Selector(("keyboardDidShow:")), name: .UIKeyboardDidShow, object: nil)
    NotificationCenter.default.addObserver(self, selector: Selector(("keyboardWillHide:")), name: .UIKeyboardWillHide, object: nil)

}

override func viewWillDisappear(_ animated: Bool) {

    NotificationCenter.default.removeObserver(self)

}

func keyboardDidShow(notification : Notification)
{

    print("keyboard shown")
    if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.cgRectValue.size
    {

        print(keyboardSize)

    }


}

func keyboardWillHide(notification : Notification)
{



}

老实说,我无法找到我出错的地方。我不断收到问题陈述中所述的错误。

0 个答案:

没有答案