swift2 UIPickerView默认行

jyztefdp  于 2022-11-06  发布在  Swift
关注(0)|答案(1)|浏览(191)

如果我想在视图控制器以[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数据源和委托。

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) {

}
ttisahbt

ttisahbt1#

viewDidLoad方法中,将选择器视图的选定行设置为任意初始行。这是Swift 3的代码。根据Swift 2的需要进行调整。

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

相关问题