My UIWebView loads a contenteditable html content. I want to let the UIWebView get focused and show keyboard in the UIWebView.
I use [self.webview becomeFirstResponder]
, but it doesn't work. Is there any work around method?
Thanks.
This is now possible in iOS 6. See the boolean keyboardDisplayRequiresUserAction in UIWebView. Once set to NO then you can use focus() to set the cursor.
In iOS 6 > you need to 1) set your webview to keyboardDisplayRequiresUserAction = NO, and 2) call focus. Here's the code:
self.webView.keyboardDisplayRequiresUserAction = NO; // put in viewDidLoad
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.webView
stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].focus()"];
return YES;
}
You can use document.getElementById('someId').focus() as an alternative. I've set the textField as the delegate and used the delegate method textFieldShouldReturn which fires when the return key is pressed.
UIwebview is not editable and you can not make it first responder. Where as you can use javascripts for that purpose , try out this answer
UIWebView with contentEditable (html editing), first responder handling?
need set "Visible at Launch" checkbox in you window object - keyboard will show automaticaly on input field
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With