我的UIWebView加载了一个令人满意的html内容。我想让UIWebView聚焦并在UIWebView中显示键盘。
我使用[self.webview becomeFirstResponder]
,但它不起作用。有什么工作方法吗?
感谢。
答案 0 :(得分:8)
现在可以在iOS 6中使用。请参阅UIWebView中的boolean keyboardDisplayRequiresUserAction。设置为NO后,您可以使用focus()设置光标。
答案 1 :(得分:2)
在iOS 6中>你需要1)将你的webview设置为keyboardDisplayRequiresUserAction = NO,以及2)调用焦点。这是代码:
self.webView.keyboardDisplayRequiresUserAction = NO; // put in viewDidLoad
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[self.webView
stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].focus()"];
return YES;
}
您可以使用document.getElementById('someId')。focus()作为替代方案。我已将textField设置为委托,并使用了当按下返回键时触发的委托方法textFieldShouldReturn。
答案 2 :(得分:1)
UIwebview不可编辑,您无法将其作为第一响应者。 你可以在哪里使用javascripts,试试这个答案
UIWebView with contentEditable (html editing), first responder handling?
答案 3 :(得分:1)
需要在窗口对象中设置“启动时可见”复选框 - 键盘将自动显示在输入字段
上