2

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?

Community
  • 1
  • 1

3 Answers3

4

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

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
1

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

- (BOOL)disablesAutomaticKeyboardDismissal {
  return NO;
}

Have a look at that answer.

Community
  • 1
  • 1
0

try

webView.delegate = self;

and inside the -webViewDidFinishLoad: delegate method

[webView resignFirstResponder];
holex
  • 23,961
  • 7
  • 62
  • 76
iOS Test
  • 1,103
  • 1
  • 11
  • 18
  • @Erik try your approaches inside delegate methods: - (void)webViewDidStartLoad:(UIWebView *)awebView OR - (void)webViewDidFinishLoad:(UIWebView *)aWebView instead of you tried earlier – iOS Test Jul 16 '12 at 13:14