gpt4 book ai didi

ios - 如何在 Swift 3 的 UIPickerView 中获取所选行的字符串值?

转载 作者:可可西里 更新时间:2023-11-01 00:20:42 26 4
gpt4 key购买 nike

func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
switch pickerView {
case sexPicker:
return sex.count
case agePicker:
return age.count
case proPicker:
return profession.count
default:
return 0
}
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
switch pickerView {
case sexPicker:
return sex[row]
case agePicker:
return age[row]
case proPicker:
return profession[row]
default:
return ""
}
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
switch pickerView {
case sexPicker:
sexText.text = sexPicker.selectedRow(inComponent: 1) *// This gives only the row value but need string value*
case agePicker:
ageText.text = agePicker.selectedRow(inComponent: 1)
case proPicker:
professionText.text = pickerView(proPicker, titleForRow: 0, forComponent: 1) // Cannot call non-function type uipickerview
default:
break
}
}

请帮我获取特定选择器 View 的选定行的字符串值。

最佳答案

很简单。请使用它的数据模型。

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

switch pickerView {
case sexPicker:
sexText.text = sex[row]
case agePicker:
ageText.text = age[row]
case proPicker:
professionText.text = profession[row]
default:
break
}

}

关于ios - 如何在 Swift 3 的 UIPickerView 中获取所选行的字符串值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48201290/

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