我想在用户开始更改 UIDatePicker 的值时触发一个操作。我的第一个直觉是使用 datePickerEditingDidBegin 方法,但似乎没有用。
Best Answer-推荐答案 strong>
直接来自文档:
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)
连接您的日期选择器 valueChanged 将事件发送到您的 IBAction
编辑:
根据文档,UIDatePicker 没有任何委托(delegate)方法,因此像 datePickerEditingDidBegin 这样的东西没有任何意义。
你必须使用 UIControlEvent 。如果 valueChanged 不适合您的需要,我可能会建议 touchDragInside 。
An event where a finger is dragged inside the bounds of the control.
其他 UIControlEvent 描述位于 here in the docs .
关于ios - 开始使用 UIDatePicker 时的操作,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/42492579/
|