Dismiss keyboard when done pressed




















Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Explaining the semiconductor shortage, and how it might end. Does ES6 make JavaScript frameworks obsolete?

Featured on Meta. Now live: A fully responsive profile. Related Hot Network Questions. Question feed. I used the following code:. The return true part of this only tells the text field whether or not it is allowed to return. You have to manually tell the text field to dismiss the keyboard or what ever its first responder is , and this is done with resignFirstResponder , like so:.

You can create an action outlet from the UITextField for the " Primary Action Triggered " and resign first responder on the sender parameter passed in:.

I hate to add the same function to every UIViewController. You can even omit this one line code by hooking delegate in Main. Then open up your assistant editor and ensure both your Main. Click on a text field and then select from the right hand side utilities panel 'Show the Connection Inspector' tab. Control drag from the 'Did End on Exit' to the above function in your swift file. Repeat for any other textfield in that scene and link to the same function.

To get automatic keyboard dismissal, I put this code inside one of the methods of my custom text field's class:. Another way of doing this which mostly uses the storyboard and easily allows you to have multiple text fields is:.

Connect all your text fields for that view controller to that action on the Did End On Exit event of each field. When the user taps the Done button on the text keyboard, a Did End On Exit event will be generated; at that time, we need to tell the text field to give up control so that the keyboard will go away.

In order to do that, we need to add an action method to our controller class. Select ViewController. Select Main. A small pop-up menu will appear containing the name of a single action, the one we just added.

Click the textFieldDoneEditing action to select it and that's it. Make sure that your textField delegate is set to the view controller from which you are writing your textfield related code in. Stack Overflow for Teams — Collaborate and share knowledge with a private group.

Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to hide keyboard in swift on pressing return key? Ask Question.

Asked 7 years, 5 months ago. Active 1 year, 6 months ago. If you attempt to unfocus a node that currently has the primary focus, Flutter will throw an exception. While this does technically work, it's not recommended as FocusNode is a ChangeNotifier and therefore needs to be disposed of properly. With the above method, a FocusNode is created and then thrown into the abyss never to be seen again. An error has occurred. Please e-mail frank flutterigniter. Flutter Igniter Helping pragmatic app developers.

Articles Contact. Asked by BiggestMarioFan. Copy to clipboard Share this post. Copied to Clipboard. Add a Comment. Where do you test that answer is correct?



0コメント

  • 1000 / 1000