user187676
user187676

Reputation:

UIWebView won't hide keyboard

I need to hide the keyboard as soon as a page starts loading. I've tried all commonly suggested approaches discussed e.g. here

Following approaches have no effect on the keyboard

[webView endEditing:YES];
[webView stringByEvaluatingJavaScriptFromString:@"document.activeElement.blur();"];
[webView stringByEvaluatingJavaScriptFromString:@"window.blur();"];

I invoke them in -webView:shouldStartLoadWithRequest:navigationType:

What am I doing wrong? Any suggestions?

Upvotes: 2

Views: 3142

Answers (3)

Yanelsy Rivera
Yanelsy Rivera

Reputation: 41

Thanks for your answer. i write this methods

- (BOOL)disablesAutomaticKeyboardDismissal {
  return NO;
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [webView endEditing:YES];
}

works for me

Upvotes: 4

user187676
user187676

Reputation:

The problem was that UIViewController's returned YES here for UIModalPresentationFormSheet.

- (BOOL)disablesAutomaticKeyboardDismissal {
  return NO;
}

Have a look at that answer.

Upvotes: 1

iOS Test
iOS Test

Reputation: 1103

try

webView.delegate = self;

and inside the -webViewDidFinishLoad: delegate method

[webView resignFirstResponder];

Upvotes: 0

Related Questions