I am using a UIDatePicker in my app to allow picking time:
let startTimePicker = UIDatePicker()
startTimePicker.addTarget.preferredDatePickerStyle = .compact
startTimePicker.addTarget.datePickerMode = .time
However, I only want user to be able to pick this time after they have entered a password correctly. For incorrect password, I want the tap on the picker to be cancelled.
I am able to detect when tap occurs by using editingDidBegin:
startTimePicker.addTarget(self, action: #selector(beginChangingTimes(sender:)), for: .editingDidBegin)
However, I am unable to cancel the tap or at least prevent it from showing the picker until correct password has been entered.
In my beginChangingTimes(sender:) function, I have tried things like setting the picker isEnabled to false then true, setting isUserInteractionEnabled to false then true, calling resignFirstResponder() on the picker, and calling endEditing(true) on the picker. None of these seem to cancel the tap and it just keeps showing the actual picker UI:
How can I cancel it?
