Show keyboard in contenteditable UIWebView programmatically

前端 未结 4 950
盖世英雄少女心
盖世英雄少女心 2020-12-30 15:29

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 becomeFirstR

相关标签:
4条回答
  • 2020-12-30 15:50

    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?

    0 讨论(0)
  • 2020-12-30 15:58

    need set "Visible at Launch" checkbox in you window object - keyboard will show automaticaly on input field

    0 讨论(0)
  • 2020-12-30 16:05

    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.

    0 讨论(0)
  • 2020-12-30 16:05

    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.

    0 讨论(0)
提交回复
热议问题