gpt4 book ai didi

swift - 当 PickerView 第一次弹出/用户尚未开始任何访问时,如何从 PickerView 获取第一个值

转载 作者:行者123 更新时间:2023-11-30 12:19:12 24 4
gpt4 key购买 nike

我尝试使用此方法selectedRow(inComponent: 0),但它对我不起作用。当选择器不活动时,有什么方法可以从选择器中获取第一个/默认值吗?

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return countries.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return countries[row].name
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
country.text = countries[row].name //`country.text` is just textField
}
}

最佳答案

没什么大不了的-

只需将选择器 View 定义为全局并访问 objectAtIndex(0)

并在viewDidLoad()中写入这行代码

不准确,但类似这样-

@IBOutlet var yourPicker: UIPickerView! = UIPickerView()

var yourArray = ["Apple", "Samsung", "Nokia"]


override func viewDidLoad() {
super.viewDidLoad()
yourPicker.text = yourArray[0]
}

关于swift - 当 PickerView 第一次弹出/用户尚未开始任何访问时,如何从 PickerView 获取第一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45004056/

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