我正在嘗試在我的KeyboardScrollController
類中獲取鍵盤通知,但我無法識別選擇器UIKeyboardWillHideNotification
和UIKeyboardDidShowNotification
。UIKeyboardWillHideNotification上無法識別的選擇器
這是我簡單的實現:
public class KeyboardScrollController
{
public func subscribeForKeyboardNotifications()
{
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWasShown:", name: UIKeyboardDidShowNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "keyboardWillHide:", name: UIKeyboardWillHideNotification, object: nil)
}
public func unsubscribeForKeyboardNotifications()
{
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardDidShowNotification, object: nil);
NSNotificationCenter.defaultCenter().removeObserver(self, name: UIKeyboardWillHideNotification, object: nil);
}
//MARK: Keyboard events
public func keyboardWasShown(notification: NSNotification)
{
}
public func keyboardWillHide(notification: NSNotification)
{
}
}
但鍵盤應提交每次都與此錯誤崩潰:
*** NSForwarding: warning: object 0x7fdc8d882730 of class 'KeyboardScrollController' does not implement methodSignatureForSelector: -- trouble ahead Unrecognized selector -[KeyboardScrollController keyboardWillHide:]
我試圖與Selecor("keyboardWillHide:")
,但沒有作出任何區別。
這裏有什麼問題?我已經在Objective-C中實現了這幾次,但我無法在Swift中使用它。