开发者

hide keyboard when go button is pressed on uiwebview

Here is my context: I have a webview with a simple form on it (one input type="text"), and I would like two things: - when I press the Go button the keyboard should disappear - I don't want the 开发者_StackOverflow社区prev/next done toolbar on the keyboard

I tried a lot of solutions found here and there, (like this one iPhone keyboard in UIWebView does not go away nothing working at all :/

Any pointers/input I could try?

Thanks by advance!


For removing the keyboard, if you know the ID of the TextField you could try adding your class as the WebView Delegate and injecting some Javascript to hide the Keyboard like so (The Class where you set up the Delegate must have the UIWebViewDelegate Protocol in the interface declaration):

// Where you set up your WebView, add a class as a Delegate (self in this case)
[webView setDelegate:self];

Now you need to have the Delegate Method which is called when a new page is requested

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('myInput').blur();"];
    return YES;
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    [self.myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[textField text]]]];

    return YES;
}

CHECK THIS!!!

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜