Search This Blog

Wednesday, December 29, 2010

resignFirstResponder does not hide keyboard in presentModalViewController

For some great "Apple" reason, when the input elements are in a modal view controller, resignFirstResponder just loses the focus from the element. The keyboard stays visible.

After searching for a long time, I found 2 explanations for the same.
1. Its a bug!
2. Its a feature! Apple kept it that way to avoid the keyboard coming up and going down when switching between input elements in the modal form. B******T!

So the workaround I came up with is:
- (BOOL)textViewShouldEndEditing:(UITextView *)textView {
NSArray *arrWindows = [[UIApplication sharedApplication] windows];

if ([arrWindows count] > 1) {
UIWindow *keyboardWindow = [arrWindows objectAtIndex:1];
[keyboardWindow setHidden:YES];
return YES;


horea piper said...

Where I have the same issue.
Please tell me where do I put this code?
Thank you!

V'Raj Kanwade said...

Sorry, but this was done a long time back and I am not sure if this is still applicable.