views:

297

answers:

3

I am loading an HTML page that has a form. I would like to be able to dismiss the keyboard when the user clicks on GO or if he clicks on the SUBMIT button on the HTML page.

If the user decides he doesn't want to fill out the form, I also need a way to dismiss the keyboard.

Not sure how to do this.

A: 

I'm not completely familiar with UIWebView, but normally you would dismiss your keyboard like so...

[textField resignFirstResponder];

By doing that, the keyboard would be dismissed...

To have the keyboard be dismissed when say the user clicks the return button, you would need to implement the delegate method.

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{   
    [textField resignFirstResponder];
    return YES;
}

Apple's documentation has a full list of methods for the UITextFieldDelegate.

Avizzv92
Unfortunately UIWebView doesn't have any delegate methods like UITextField. Any other thoughts?
Sheehan Alam
Perhaps your question is answered here...http://stackoverflow.com/questions/389825/dismiss-iphone-keyboard
Avizzv92
This approach simply does not work for UIWebView. See my answer above for a solution.
Sam Soffes
+1  A: 

You can use javascript to take the focus away from the HTML text field using blur:

document.foo.bar.myinput.blur();
dbarker
also, check this out: http://stackoverflow.com/questions/866419/iphone-keyboard-in-uiwebview-does-not-go-away
dbarker
+2  A: 

A more concise way without needing to know what element is selected is the following:

[webView stringByEvaluatingJavaScriptFromString:@"document.activeElement.blur()"];
Sam Soffes