开发者

Keyboard not Appearing when Tapping Text Box in UIWebView

开发者 https://www.devze.com 2023-03-12 16:55 出处:网络
I have a UITabViewController set up with two tabs, the second containing a web browser. The keyboard will not appear in开发者_StackOverflow my App unless I first display and dismiss a UIAlertView in t

I have a UITabViewController set up with two tabs, the second containing a web browser. The keyboard will not appear in开发者_StackOverflow my App unless I first display and dismiss a UIAlertView in the first tab. What could possibly be wrong?


Solved; I accidentally removed:

[window makeKeyAndVisible];


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";


Not a lot to go on but if you have textfield visually displayed but it will not evoke the keyboard when tapped then most likely you have an issue with focus i.e. the view containing the textfield does not believe it should intercept taps. This usually occurs because another view is visually in-front (below in the logical view hierarchy) of the view containing the text field. Presumably, displaying and then dismissing the alert alters the view hierarchy and lets the textfield intercept taps.

That's what I would check first.


For me the issue was a 3rd party lib I used DCIntrospect(very recommended), it has a bug which prevents from the Keyboard to appear in UIWebViews. An issue was open https://github.com/domesticcatsoftware/DCIntrospect/issues/36


I found that [(window) makeKeyAndVisible] did the trick here.

If you are trying to use makeKeyAndVisible and it doesn't seem to do anything, very likely you are sending that message to a null object--that is what I ran into. Use NSLog() to check the identity of the Window that you will be sending that message to.

Once I found the right Window object, it worked fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号