gpt4 book ai didi

arrays - 如何在 UIPickerView 中显示所需的行?

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

我已经知道数组中的数据,并且我需要在加载应用程序时显示选定的行。例如,我如何在开始时选择“四”?

enter image description here

let arrayOfNumbers = ["One", "Two", "Three", "Four", "Five"]

override func viewDidLoad() {
super.viewDidLoad()
pickerTest.delegate = self
pickerTest.dataSource = self
}

@IBOutlet weak var pickerTest: UIPickerView!

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

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return arrayOfNumbers.count
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return arrayOfNumbers[row]
}

最佳答案

pickerTest.selectRow(4, inComponent: 0, animated: true)

关于arrays - 如何在 UIPickerView 中显示所需的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55402512/

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