iOS UIDatePicker - disable KEYPAD entry

54 views Asked by At

I have a UIDatePicker displayed with a WHEEL mode, but when I click on a date, the keyboard comes up, letting me enter a date from KEYPAD. How to disable this ridiculous behavior (why would anyone want that anyway???)

1

There are 1 answers

3
DonMag On

Apple's documentation on this is rather lacking -- I haven't been able to find any reference to that functionality.

However, it is clearly built-in as a convenient method for a user to enter the time with the Keypad.

You can prevent the Keypad from showing like this:

@IBOutlet var datePicker: UIDatePicker!

override func viewDidLoad() {
    super.viewDidLoad()
    
    datePicker.addTarget(self, action: #selector(noKeypad(_:)), for: .editingDidBegin)
}
@IBAction func noKeypad(_ sender: UIDatePicker) {
    sender.resignFirstResponder()
}