Devang
Devang

Reputation: 11338

iPad : How to know Return key of iPad keyboard is pressed ? Please check image

I want to know that which method will be called when the following key is pressed.

keyboard screenshot

I want to start action on above key press.

How do I know this is pressed ?

Upvotes: 4

Views: 4621

Answers (4)

Maulik
Maulik

Reputation: 19418

Use keyboard hide UIKeyboardWillHideNotification notification.

Example.

Upvotes: 3

Simon Lee
Simon Lee

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

Novarg
Novarg

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

Filip Radelic
Filip Radelic

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

Related Questions