iOS - Dismiss UIDatePicker presented as inputView

8vius picture 8vius · Mar 5, 2012 · Viewed 14.3k times · Source

I have a text field in my UI that when it's selected presents a UIDatePicker instead of the default keyboard, how could I set up a button as to dismiss the picker when the user is done?

Answer

mattjgalloway picture mattjgalloway · Mar 5, 2012

What I do is have my inputView as a custom view which contains a UIDatePicker and a toolbar above it with a 'Done' button wired up to a method that calls a delegate method to tell the object that owns the UITextField to dismiss the "keyboard" by calling resignFirstResponder.