For example, in this image, when I'm scrolling the UIPickerView to 2012 9 28
, what I want is that the text of the black label will change into 2012 9 28
at the same time without pressing any buttons like the Done button
我使用的是UIPickerView,我可以获取之前选择的数据,我也可以通过单击“完成”按钮将数据放入标签中,但是我cannot当我滚动时将数据放入标签中。
并且在一般情况下,
我的问题是,当我滚动 UIPickerView 时,如何获取选定的数据实时
有人可以帮助我吗? ObjectiveC 解决方案还可以,Swift 解决方案更适合我,非常感谢
目前尚不清楚您使用的是 UIPickerView 还是 UIDatePicker。
对于 UIPickerView 您需要实现 UIPickerViewDelegate。确保将委托添加到您的 ViewController 声明中,并确保在 Storyboard 中将 UIPickerView 控件的委托连接到您的视图控制器。然后实现这个功能:
func pickerView(_ pickerView: UIPickerView,
didSelectRow row: Int,
inComponent component: Int) {
}
对于 UIDatePicker,您需要将 Storyboard 中 UIDatePicker 的操作连接到视图控制器中的 @IBAction 函数,或者使用 addTarget 函数在代码中连接它:
myDatePicker.addTarget(self, action: #selector(self.respondToPicker, for: .valueChanged),
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)