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