Тип "NSNotification.Name" не имеет члена "keyboardDidShowNotification" - PullRequest
0 голосов
/ 13 сентября 2018

Я получаю эту ошибку с Swift 4.2

Тип "NSNotification.Name" не имеет члена "keyboardDidShowNotification"

Вот мой код:

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardDidShow(notification:)), name: NSNotification.Name.keyboardDidShowNotification, object: nil)

Следующий работал нормально со Swift 4, но не со Swift 4.2

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardDidShow(notification:)), name: NSNotification.Name.UIKeyboardDidShow, object: nil)

enter image description here

Apple, документ Ref: NSNotification.Name.keyboardDidShowNotification

Ответы [ 3 ]

0 голосов
/ 01 ноября 2018

Работа на Свифте 4,2

 func bindToKeyboard(){
    NotificationCenter.default.addObserver(self, selector: #selector(UIView.keyboardWillChange(_:)), name:
        UIApplication.keyboardWillChangeFrameNotification
        , object: nil)


}
0 голосов
/ 04 мая 2019

Я использовал только UIResponder.keyboardWillHideNotification, кроме использования NSNotification.Name..Это работает в SWIFT 5

NotificationCenter.default.addObserver(self, selector: #selector(KeyboardLayoutConstraint.keyboardWillShowNotification(_:)), name: UIResponder.keyboardWillShowNotification, object: nil)

NotificationCenter.default.addObserver(self, selector: #selector(self.keyboardWillHideNotification(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
0 голосов
/ 14 сентября 2018

Я полагаю, вы используете это сейчас так.

NotificationCenter.default.addObserver(
    self, 
    selector: #selector(self.keyboardDidShow(notification:)), 
    name: UIResponder.keyboardDidShowNotification, object: nil) 

/* You can substitute UIResponder with any of it's subclass */

Он указан в UIResponder doc как Свойство типа .

...