2
當我點擊文本字段爲我的應用程序的屏幕和鍵盤被顯示出來的Xcode調試器顯示此錯誤:「無法識別的選擇發送到實例」當鍵盤出現
[mainViewController keyboardWasShown]: unrecognized selector sent to instance 0x5867ac0
在mainViewController我的viewDidLoad方法這樣調用registerForKeyboardNotifications方法:
[self registerForKeyboardNotifications];
下面是它的實現(mainViewController.m):
- (void)registerForKeyboardNotifications
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
}
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
}
任何想法可能是錯誤的?
您是否直接從源代碼複製並粘貼該代碼?您似乎在使用選擇器「keyboardWasShown:」註冊通知,但是異常消息提到了一個'keyboardWasShown'選擇器(末尾的冒號很重要)。 –
對,我認爲這可能是問題...我正在測試它! – user963160
你可以讓它回覆,以便我可以投票給你嗎? :) – user963160