2016-08-14 36 views
0

我想知道選擇pickerView值的正確方法是什麼。Swift ios從pickerView中獲取選定的值

現在我的代碼是這樣的:

var timeLeft: Int? 

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 
     if pickerView.tag == 0 { 
      TimeLeftBtnLabel.text = TimeLeftPickerData[row] 

      timeLeft = row 

     } 
    } 

,或者我應該做這樣的:

var timeLeft: Int? 

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 
     if pickerView.tag == 0 { 
      TimeLeftBtnLabel.text = TimeLeftPickerData[row] 

      timeLeft = TimeLeftPicker.selectedRowInComponent(0)  

     } 
    } 

回答

0

我會去的第一個例子,因爲它更加一致。

如果將來您決定擁有多個組件,您的代碼將保持不變。

相關問題