gpt4 book ai didi

ios - 开始使用 UIDatePicker 时的 Action

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:14:04 24 4
gpt4 key购买 nike

我想在用户开始更改 UIDatePicker 的值时立即触发一个操作。我的第一直觉是使用 datePickerEditingDidBegin 方法,但似乎没有完成这项工作。

最佳答案

直接来自文档:

UIDatePicker: Responding to User Interaction

Date pickers use the Target-Action design pattern to notify your appwhen the user changes the selected date. To be notified when the datepicker’s value changes, register your action method with thevalueChanged event. At runtime the date picker calls your methods inresponse to the user selecting a date or time.

You connect a datepicker to your action method using the addTarget(_:action:for:) methodor by creating a connection in Interface Builder. The signature of anaction method takes one of three forms, which are listed in Listing 1.Choose the form that provides the information that you need to respondto 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

enter image description here

编辑:

根据文档,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 时的 Action ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42492579/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com