“unrecognized selector sent to instance” when keyboard appears
-
29-01-2021 - |
Question
When I click a text field into my app screen and the keyboard is showing up xcode debugger shows this error:
[mainViewController keyboardWasShown]: unrecognized selector sent to instance 0x5867ac0
In the viewDidLoad method of the mainViewController I'm calling the registerForKeyboardNotifications method like that:
[self registerForKeyboardNotifications];
Here's its implementation (in 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
{
}
Any idea what could be wrong?
Solution
Make sure the notification selector has the colon at the end; this is important, keyboardWasShown
and keyboardWasShown:
are different selectors.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow