[英]how to pass an NSNotification as parameter to the selector function in Swift
I'm trying to implement an UIKeyboardWillShowNotification
to handle my view position when the keyboard appear. 我正在尝试实现
UIKeyboardWillShowNotification
来处理键盘出现时的视图位置。 I add my observer: 我添加我的观察者:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow", name: UIKeyboardWillShowNotification, object: nil)
Then I have the keyboardWillShow
function: 然后我有了
keyboardWillShow
函数:
func keyboardWillShow(notification: NSNotification){
//Need to access to the notification here
}
In the function keyboardWillShow
I need to receive the NSNotification
to get access to the user information but I get this error: 在功能
keyboardWillShow
我需要接收NSNotification
才能访问用户信息,但出现此错误:
"unrecognized selector sent to instance 0x7fd993e7d020"
“无法识别的选择器已发送到实例0x7fd993e7d020”
You forgot the colon :
. 你忘记了冒号
:
。 Change it to this: 更改为此:
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillShow:", name: UIKeyboardWillShowNotification, object: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.