我知道数组中的数据,加载我的应用程序时需要显示选定的行。例如,如何在开始时选择“四个”?
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]
}
答案 0 :(得分:0)
pickerTest.selectRow(4, inComponent: 0, animated: true)