Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to dismiss keyboard on a UIWebView?

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.

like image 712
Sheehan Alam Avatar asked Apr 01 '10 19:04

Sheehan Alam


People also ask

How do you dismiss a keyboard?

Android devices have a solution; press the physical back button (provided on some mobile phones) or the soft key back button, and it closes the keyboard.

How to dismiss keyboard swift?

Via Tap Gesture This is the quickest way to implement keyboard dismissal. Just set a Tap gesture on the main View and hook that gesture with a function which calls view. endEditing . Causes the view (or one of its embedded text fields) to resign the first responder status.

How do I dismiss a swift textfield keyboard?

If you're supporting only iOS 15 and later, you can activate and dismiss the keyboard for a text field by focusing and unfocusing it. In its simplest form, this is done using the @FocusState property wrapper and the focusable() modifier – the first stores a Boolean that tracks whether the second is currently focused.


2 Answers

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

[webView stringByEvaluatingJavaScriptFromString:@"document.activeElement.blur()"];
like image 198
Sam Soffes Avatar answered Sep 28 '22 10:09

Sam Soffes


The javascript approach is clever, but this is more direct:

[webView endEditing:YES];
like image 43
Christopher Pickslay Avatar answered Sep 28 '22 09:09

Christopher Pickslay