I want to trigger an action, as soon as the user starts to change the value of the UIDatePicker. My first instinct was to use the datePickerEditingDidBegin
method but does not seem to do the job.
Straight from the docs:
UIDatePicker: Responding to User Interaction
Date pickers use the Target-Action design pattern to notify your app when the user changes the selected date. To be notified when the date picker’s value changes, register your action method with the valueChanged event. At runtime the date picker calls your methods in response to the user selecting a date or time.
You connect a date picker to your action method using the addTarget(_:action:for:) method or by creating a connection in Interface Builder. The signature of an action method takes one of three forms, which are listed in Listing 1. Choose the form that provides the information that you need to respond to the value change in the date picker.
Listing 1 Action methods for date pickers
@IBAction func doSomething() @IBAction func doSomething(sender: UIDatePicker) @IBAction func doSomething(sender: UIDatePicker, forEvent event: UIEvent)
Connect your date pickers valueChanged
send event to your IBAction
Edit:
Per the docs, UIDatePicker
doesn't have any delegate methods, therefore something like datePickerEditingDidBegin
wouldn't make any sense.
You have to use UIControlEvent
. If valueChanged
doesn't suit your needs I would maybe suggest touchDragInside
.
An event where a finger is dragged inside the bounds of the control.
Other UIControlEvent
descriptions located here in the docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With