2

I have a really weird problem with a UIWebView.

I'm using it to login users to several services, I open the UIWebView, show a HTML login page, and pressing one of the textfields opens up the keyboard, as it should.

enter image description here

Afterwards, If i try loading a different login screen in it, pressing the input doesn't show the keyboard for some reason.

enter image description here

Did any of you ever run into this weird bug ? I tried checking for [self.window makeKeyAndVisible]; like i saw some recommend but it doesnt solve the problem unfortunately :(

This is how i load the UIWebView:

[webAuth stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"];
[webAuth loadRequest: [NSURLRequest requestWithURL:  [NSURL urlWithString:@"http://whatever"] ]];

First line is for clearing the page (tried removing it , it doesnt solve the keyboard problem)

Shai Mishali
  • 9,224
  • 4
  • 56
  • 83
  • [self.view endEditing:YES]; to force resign first responder. I don't test this, but you can try – NeverBe Feb 18 '12 at 12:39
  • 1
    @NeverBe thanks, but this doesn't anser my question unfortunately, i need to understand why on the second load , the webview doesn't respond when an input text is selected... (keyboard doesnt come up) – Shai Mishali Feb 18 '12 at 14:31
  • 1
    I thought about that but it just sounds like such a dirty workaround ... I'll do that for now. Thanks. – Shai Mishali Feb 18 '12 at 14:44
  • I have the same problem with keyboard not showing, but seems to be iOS Version dependend. I test a form dialog which is being loaded by a UIWebView in iOS 4.3 and iOS 5.0 Simulator and the keyboard appears as expected (when tapping on the input field). But when i test the same in an iOS 5.1 Simulator (and also on a device with that version) it doesn't appear. Do you have any suggestions, what in my case could be the problem? Thx – NicTesla Jul 02 '12 at 07:55
  • I solved it already! I added [window makeKeyAndVisible]; in the application:didFinishLaunchingWithOptions: method (as described in here in this forum) and that did the trick! – NicTesla Jul 06 '12 at 10:10

2 Answers2

2

I'm really sorry if I missed something, but I can't reproduce your error. Could you maybe specify your setup in more detail? (I'd rather added this post as a comment, but don't have the reputation for it yet, sorry -.- please feel free to change this answer into a comment)

What I do:

  1. I use iOS SDK 5.0 and tried on the iOS5.0 simulator and an iPhone4 with iOS5.0
  2. I created a simple view-based app and dragged in a button and a webview into the nib file
  3. I call the first website in the viewDidLoad, which is the Facebook login

    - (void)viewDidLoad {
      [super viewDidLoad];
      [self.webAuth stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"];
      [self.webAuth loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://facebook.com"]]];
    }
    
  4. I use the aforementioned button to call the second website, Twitter login

    - (IBAction)showWebsite:(UIButton *)sender {
        [self.webAuth stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML = \"\";"];
        [self.webAuth loadRequest: [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://twitter.com/#!/login"]]];
    }
    
  5. I login on Facebook, then press the button, and tap on any Twitter login input field

  6. Everything, including the keyboard, works as intended
JiaYow
  • 5,207
  • 3
  • 32
  • 36
  • When doing it in a different project it works, I'm still not sure what in my current project causes this. Ill keep looking into it. – Shai Mishali Feb 21 '12 at 09:37
1

I'm writing this just in case someone else will ever come across this -
It seems what caused the problem was using SVProgressHUD to present a loader while the web pages load. I'm not sure how but when i comment them out everything works as expected.

Update: Sam has fixed the SVProgressHUD componenet and now it works with no issues on viewDidLoad

Shai Mishali
  • 9,224
  • 4
  • 56
  • 83
  • I had the same problem. Thanks for pointing out SVProgressHUD! Though I think the last version fixed the problem with the use of GCD: https://github.com/samvermette/SVProgressHUD – Sylvain Guillopé Apr 25 '12 at 15:06
  • Yup, Sam fixed it just a couple of days ago. – Shai Mishali Apr 26 '12 at 10:16
  • Do you buy chance know what the actual cause of this issue was, or have the commit in SVProgresssHUD that fixed it? I am experiencing a similar issue, where when I call loadRequest a second time on a UIWebView, the keyboard no longer displays. – wildabeast Nov 01 '12 at 05:14
  • Nevermind ... this did it for me http://stackoverflow.com/questions/11869918/cant-show-a-keyboard-on-uiwebview-on-new-project-on-xcode-4-4. – wildabeast Nov 01 '12 at 05:19