[英]Swift 3: Unrecognised selector sent to instance (KeyboardWillShow)
我在堆棧溢出時搜索了很多關於它的信息,但根據他們的解決方案,我的程序與提到的相同,但仍然無效。
func subscribeToKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector:Selector(("keyboardWillShow:")), name:NSNotification.Name.UIKeyboardWillShow, object: nil)
}
func keyboardWillShow(notification:NSNotification) {
view.frame.origin.y -= getKeyboardHeight(notification: notification)
}
你的選擇器參數應該是#selector(keyboardWillShow)
,如下所示:
func subscribeToKeyboardNotifications() {
NotificationCenter.default.addObserver(self, selector:#selector(keyboardWillShow), name: .UIKeyboardWillShow, object: nil)
}
func keyboardWillShow(notification:NSNotification) {
view.frame.origin.y -= getKeyboardHeight(notification: notification)
}
如果您不使用#selector,那么它將給出NSType的未捕獲異常,因此它將終止該應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.