Reputation: 1476
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.
Upvotes: 5
Views: 9530
Reputation: 19642
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.
Upvotes: 2
Reputation: 485
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.
Upvotes: 8
Reputation: 166
need set "Visible at Launch" checkbox in you window object - keyboard will show automaticaly on input field
Upvotes: 1
Reputation: 721
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?
Upvotes: 1