Shai Mishali
Shai Mishali

Reputation: 9382

UIWebView doesn't show keyboard when focusing on text field on the second load

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)

Upvotes: 2

Views: 4419

Answers (2)

Shai Mishali
Shai Mishali

Reputation: 9382

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

Upvotes: 1

JiaYow
JiaYow

Reputation: 5227

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

Upvotes: 2

Related Questions