Swift UIDatePicker for text field input - how to make UIDatePicker disappear?
You could try something as gestureRecognizer
to make the UIDatePicker disappear:
@objc func viewTapped(gestureRecognizer: UITapGestureRecognizer) {
view.endEditing(true)
}
This is what I used in my app so when the user taps on anywhere on the screen the UIDatePicker goes away!
You call resignFirstResponder
on the text field:
@IBAction func DoneButton(sender: UIButton) {
dateField.resignFirstResponder()
}
Also, it's not a great idea to have a method and a property with the same name - not sure about precedence there, but chances are it could be confusing at some point.