2

アプリ画面のテキストフィールドをクリックしてキーボードが表示されると、xcodeデバッガーに次のエラーが表示されます。

[mainViewController keyboardWasShown]: unrecognized selector sent to instance 0x5867ac0

mainViewControllerのviewDidLoadメソッドで、次のようなregisterForKeyboardNotificationsメソッドを呼び出しています。

[自己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
{

}

何が間違っている可能性がありますか?

4

1 に答える 1

4

通知セレクターの最後にコロンがあることを確認してください。これは重要でkeyboardWasShownありkeyboardWasShown:、異なるセレクターです。

于 2011-09-25T23:19:13.433 に答える