SolidSnake4444
SolidSnake4444

Reputation: 3587

iPad "dismiss keyboard" button (lower right), how do I detect when this occurs? What function tells me it was pressed?

I have an ipad app that when you are in landscape view, the view will move up when the keyboard is brought in. When you press done on the keyboard, textFieldShouldReturn and textFieldShouldEndEditing are called in which case, I move the view down in shouldEndEditing.

If the user presses the dismiss keyboard button, the keyboard does poof, yet the view is still stuck floating where I moved it.

I need to know how or what function is called when that button is pressed so I can redirect the function to textFieldShouldEndEditing.

Thanks!

Upvotes: 24

Views: 18080

Answers (3)

Chris Allinson
Chris Allinson

Reputation: 1872

When the "lower keyboard" button is pressed, the textfield delegate method of:

-(BOOL)textFieldShouldReturn:(UITextField *)textField

Won't be called.

When either the "lower keyboard" or "return button" are pressed, the:

-(void)textFieldDidEndEditing:(UITextField *)textField

Will be called.

I use a variable NSString *lowerKeyboardButtonPressed initially set to @"" which I set to @"N" in the textfieldShouldReturn method ... then in the textFieldDidEndEditing method I check to see if it is set to @"N" ... then I know if the return key or lower keyboard key was pressed. The last line in my textFieldDidEndEditing method sets the variable back to @"".

Upvotes: 14

Woolie
Woolie

Reputation: 23

If you press the keyboard dismiss button and you have a hardware keyboard attached, then the willHide will only be called if you don't have an input accessory view. At which point you need to adjust in the willShow as well (which will have a negative difference between the UIKeyboardFrameBeginUserInfoKey and UIKeyboardFrameEndUserInfoKey keys).

Upvotes: 2

Sharjeel Aziz
Sharjeel Aziz

Reputation: 8535

You can listen for keyboard hide UIKeyboardWillHideNotification notification.

Example code is here http://developer.apple.com/iphone/library/samplecode/KeyboardAccessory/Listings/Classes_ViewController_m.html

Upvotes: 26

Related Questions