如果我想在视图控制器以[8]或任何其他行号开头时拥有默认行,我该如何进行该操作?
var pickerData = ["2x2","4x4","6x6","8x8","12x12","12.5x12.5","13x13","13.5x13.5","14x14","14.5x14.5","15x15","15.5x15.5","16x16","16.5x16.5","17x17","17.5x17.5","18x18","18.5x18.5","19x19","19.5x19.5","20x20","20.5x20.5","21x21","21.5x21.5","22x22","22.5x22.5","24x24","24.5x24.5","32x32","24x48"]
override func viewDidLoad() {
super.viewDidLoad()
totalTilesLabel.text = pickerData[8]
display.text = sentData
self.picker.delegate = self
self.picker.dataSource = self
}
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) {
}
答案 0 :(得分:8)
将选择器视图的选定行设置为viewDidLoad
方法中所需的任何初始行。这是Swift 3代码。根据Swift 2的需要进行调整。
self.picker.selectRow(8, inComponent: 0, animated: false)