The best answer I found was the following:
1 |
class ViewController: UIViewController,UITextFieldDelegate { |
and then create the IBOutlet for your text field like this
1 |
@IBOutlet var txtTest : UITextField = nil |
make sure that it is connected to your text field on your view in storyboard.
finally set its Delegate using
1 |
txtTest.delegate=self |
We are almost done. Now place this delegate function into your class.
1 2 3 4 5 6 7 8 9 |
func textFieldShouldReturn(_ textField: UITextField) -> Bool // called when 'return' key pressed. return NO to ignore. { textField.resignFirstResponder() return true; } |
Right here: https://stackoverflow.com/questions/24908966/hide-keyboard-for-text-field-in-swift-programming-language