gpt4 book ai didi

ios - UIPickerView 默认行

转载 作者:可可西里 更新时间:2023-11-01 04:24:48 26 4
gpt4 key购买 nike

如果我想在 View Controller 以 [2] 或任何其他行号开始时拥有默认行,我该如何实现?

var pickerData = ["2x2","4x4","6x6","8x8","12x12"]    


override func viewDidLoad() {
super.viewDidLoad()

totalTilesLabel.text = pickerData[8]


display.text = sentData
self.picker.delegate = self
self.picker.dataSource = self

}

这是 UIPicker 数据源和委托(delegate)。

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

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

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

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

}

最佳答案

viewDidLoad 方法中将选取器 View 的选定行设置为您想要的任何初始行。这是 Swift 3 代码。根据需要针对 Swift 2 进行调整。

self.picker.selectRow(8, inComponent: 0, animated: false)

关于ios - UIPickerView 默认行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40982940/

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