This could be a dumb question but how can I get out of a selected UITextField if I click anywhere on the screen? I need this in Swift, not Obj-c please. Thank you.
Asked
Active
Viewed 1,071 times
-1
-
2Possible duplicate of [iphone, dismiss keyboard when touching outside of UITextField](http://stackoverflow.com/questions/5306240/iphone-dismiss-keyboard-when-touching-outside-of-uitextfield) – jtbandes Mar 31 '16 at 18:57
2 Answers
3
You have to set the end editing as true.
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?){
view.endEditing(true)
super.touchesBegan(touches, withEvent: event)
}

David
- 3,285
- 1
- 37
- 54

Arun Gupta
- 2,628
- 1
- 20
- 37
0
U can do like this
override func touchesBegan(_ touches: Set<UITouch>,
withEvent event: UIEvent?) { yourTextfield.resignFirstResponder()}
in your view controller

Shreesha Kedlaya
- 340
- 4
- 19