gpt4 book ai didi

ios - Swift ios 从 pickerView 获取选定值

转载 作者:行者123 更新时间:2023-11-30 13:09:09 25 4
gpt4 key购买 nike

我想知道获取所选 pickerView 值的正确方法是什么。

现在我的代码是这样的:

var timeLeft: Int?

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if pickerView.tag == 0 {
TimeLeftBtnLabel.text = TimeLeftPickerData[row]

timeLeft = row

}
}

或者我应该这样做:

var timeLeft: Int?

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if pickerView.tag == 0 {
TimeLeftBtnLabel.text = TimeLeftPickerData[row]

timeLeft = TimeLeftPicker.selectedRowInComponent(0)

}
}

最佳答案

我会选择第一个例子,因为它更一致。

如果将来您决定使用多个组件,您的代码将保持不变。

关于ios - Swift ios 从 pickerView 获取选定值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38943079/

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