Reputation: 11338
I want to know that which method will be called when the following key is pressed.
I want to start action on above key press.
How do I know this is pressed ?
Upvotes: 4
Views: 4621
Reputation: 22334
Observe the UIKeyboardDidHideNotification
notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
And...
- (void)keyboardDidHide:(NSNotification *)aNotification {
}
You can also change it to UIKeyboardWillHideNotification
if you need to be notified BEFORE the keyboard starts to disappear.
Upvotes: 13
Reputation: 7450
Not sure if it's exactly what you are looking for, but you can try using notifications. Don't have Mac nearby atm, so just copy-pasting the code from github. I have that code in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
and then 2 methods:
- (void)keyboardWillShow:(NSNotification *)notification {
}
- (void)keyboardWillHide:(NSNotification *)notification {
}
Hope it helps
Upvotes: 3
Reputation: 26683
That's not a return key. Return key is the one above it. That's simply a button that dismisses the keyboard and you can't recognize it via standard text input methods. You need to register for UIKeyboardWillHideNotification
notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
and implement that method:
- (void)keyboardWillHide:(NSNotification *)notification
{
// do whatever you want to do when keyboard dismiss button is tapped
}
Upvotes: 5