Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

resignFirstResponder not hiding keyboard on textFieldShouldReturn

I have a view with a UITextField which should hide the keyboard when return is pressed.

My function is this:

- (BOOL)textFieldShouldReturn:(UITextField *)textField {  if ( textField == userPassword ) {   [textField resignFirstResponder];  }  return YES; } 

Normally the keyboard should be hidden but it stays on the screen. resignFirstResponder is correctly called. What am I missing?

like image 389
favo Avatar asked Jun 26 '10 17:06

favo


People also ask

How to dismiss keyboard on return Key in iOS?

If you have a UITextField and you want to hide the keyboard when the user is pressing the return key, use the textFieldShouldReturn function. Be sure you have set the textField. delegate = self in your viewDidLoad() function.


2 Answers

I see you have the iPad tag on this. Do you happen to be presenting a modal view using UIModalPresentationFormSheet? If so, it looks like this is a limitation of the FormSheet modal presentation (either Apple is doing it intentionally for some reason, or it is a bug). See these other questions for more details:

Modal Dialog Does Not Dismiss Keyboard

Modal View Controller with keyboard on landscape iPad changes location when dismissed

like image 127
Brandon Avatar answered Oct 04 '22 01:10

Brandon


There is this helpful method which allows you to dismiss the keyboard when presenting the Modal Dialog:

 - (BOOL)disablesAutomaticKeyboardDismissal { return NO; } 

This will override the default behavior of the modal dialog set by Apple and allow you dismiss the keyboard. It is in the UIViewController Class.

I hope this helps someone!

like image 31
tony.stack Avatar answered Oct 03 '22 23:10

tony.stack