Keyboard not Appearing when Tapping Text Box in UIWebView

后端 未结 5 1904
南方客
南方客 2020-11-30 15:29

I have a UITabViewController set up with two tabs, the second containing a web browser. The keyboard will not appear in my App unless I first display and dismis

5条回答
  •  囚心锁ツ
    2020-11-30 16:00

    The solution mentioned here didn't work for me. I had a persistent error that seemed to be an issue with iOS, or at least my build settings. I came up with a workaround. If you're still stuck like I was, try this. I think it will work. Here it is briefly. Check out my post if you need more detail.

    Put this into your web view's delegate:

    - (BOOL)webView:(UIWebView *)v shouldStartLoadWithRequest:(NSURLRequest *)r navigationType:(UIWebViewNavigationType)t {
    
      NSString *requestString = [[r URL] absoluteString];
    
      if ([requestString hasPrefix: @"yourURLPrefix:"] ) {
          if ([requestString hasPrefix: @"yourURLPrefix:keyboardFix"] ) {
              [v.window makeKeyAndVisible];
          }
    }
    

    Put this into the onFocus event handler of any input element you need to reliably bring up the keyboard:

    document.location = "yourURLPrefix:keyboardFix";
    

提交回复
热议问题