如果我想在视图控制器以[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) {
}
1条答案
按热度按时间ttisahbt1#
在
viewDidLoad
方法中,将选择器视图的选定行设置为任意初始行。这是Swift 3的代码。根据Swift 2的需要进行调整。