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
Era
  • 30,460
  • 24
  • 136
  • 197

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
  • 38,454
  • 20
  • 92
  • 120
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
Era
  • 30,460
  • 24
  • 136
  • 197
0

try

webView.delegate = self;

and inside the -webViewDidFinishLoad: delegate method

[webView resignFirstResponder];
holex
  • 23,814
  • 7
  • 61
  • 76
iOS Test
  • 1,093
  • 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