在我的選取器視圖中,我希望默認行爲零。該行的值爲1.我希望除了按鈕之外能夠在視圖控制器上不觸及任何內容。我知道有類似的問題,但他們不適合我。PickerView選中默認行,但返回零,除非選取器視圖被移動
override func viewWillAppear(_ animated: Bool) {
self.pickerView.delegate = self
self.pickerView.dataSource = self
self.pickerView.selectRow(0, inComponent: 0, animated: true)
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return String(numbers[row])
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return numbers.count
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
therow = pickerView.selectedRow(inComponent: 0) + 1
}
然後
@IBAction FUNC submitTapped(_發件人:任何){ 打印(therow) }
當我點擊提交併打印在0行中的值它是0,但如果我擺動選擇器視圖並將其放回第0行,則它會打印1.我需要能夠在選取器視圖上不觸及任何內容,並使其返回默認行的適當值。
我想你應該在didSelectRow方法 –
theRowIndex使用「theRowIndex =行」是未知@SaurabhPrajapati –
是'didSelectRow'什麼時候只有按下按鈕纔會打電話? – Sweeper