繁体   English   中英

如何将NSNotification作为参数传递给Swift中的选择器函数

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM