我正在尝试实现 UIKeyboardWillShowNotification
以在键盘出现时处理我的 View 位置。
我添加我的观察者:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow", name: UIKeyboardWillShowNotification, object: nil)
然后我有 keyboardWillShow
功能:
func keyboardWillShow(notification: NSNotification){
//Need to access to the notification here
}
在函数 keyboardWillShow
中,我需要接收 NSNotification
才能访问用户信息,但出现此错误:
"unrecognized selector sent to instance 0x7fd993e7d020"
最佳答案
您忘记了冒号 :
。将其更改为:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
关于ios - 如何将 NSNotification 作为参数传递给 Swift 中的选择器函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28326601/