By sonics876


2011-06-10 22:27:05 8 Comments

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 dismiss a UIAlertView in the first tab. What could possibly be wrong?

5 comments

@Matt Mc 2012-09-12 04:23:39

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.

@benlozano 2012-08-06 16:30:50

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

@Dmitry 2012-08-08 16:57:24

But how to access to window for UIWebView on storyboard?

@benlozano 2012-08-08 18:19:47

I gather that you don't know which UIWindow is associated with your UIWebView... sorry if I misunderstand you. I'll provide a code snippet for you in my answer. I'm not testing it, but I'm sure it will work.

@Dmitry 2012-08-08 18:30:25

benlozano, thanks for your answer! I have tried [myWebView.window makeKeyAndVisible] but keyboard doesn't appear:(

@benlozano 2012-08-08 18:35:00

Actually, myWebView.window may have the same effect as the code I provided... I never even bothered to look for a window property. Try my code and tell me how it works out. (shows what I know.)

@Dmitry 2012-08-08 18:39:38

I have tried myWebView.window and code provided by you - keyboard doesn't appear:( webViewSuperview is not nil. Is there any hard method to call keyboard?

@benlozano 2012-08-08 18:41:57

Unfortunately, there isn't. I went through this same thing. Have you confirmed that the code is reaching the shouldStartLoadWithRequest function's "keyboardFix" block with some kind of debugging message?

@Dmitry 2012-08-08 18:44:56

Yes, the code with makeKeyAndVisible executed successfully. But there is no keyboard:(

@benlozano 2012-08-08 18:46:37

Can you show me briefly how you're inserting the javascript code into your onfocus?

@benlozano 2012-08-08 18:46:50

@Dmitry 2012-08-08 18:49:13

I should show a keyboard on a webpage that is shown without keyboard on mobile Safari too. But MacOS Safari works fine. I may send you an URL to this webpage if you are ready to help to solve the issue. Thanks.

@sonics876 2011-06-14 00:39:07

Solved; I accidentally removed:

[window makeKeyAndVisible];

@boliva 2011-11-16 19:29:28

goddamn I've been hitting my head against the keyboard all morning and this was it, thanks!!

@Dmitry 2012-08-08 16:48:56

But [myWebView.window makeKeyAndVisible]; din't help me:(

@Dmitry 2012-08-08 16:59:06

How to access to correct window variable?

@Aviel 2011-10-29 19:31:48

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

@TechZen 2011-06-10 22:48:35

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.

Related Questions

Sponsored Content

92 Answered Questions

1 Answered Questions

3 Answered Questions

Disable keyboard automatically after tap on another UITextField

2 Answered Questions

2 Answered Questions

[SOLVED] Keyboard gets dismissed when tapping into UIWebViews

1 Answered Questions

[SOLVED] Force UIKeyboardAppearance Reload

1 Answered Questions

1 Answered Questions

Weird iOS5 glitch when keyboard appears after selecting textfield

1 Answered Questions

Sponsored Content