2016-08-14 8 views
0

選択したpickerViewの値を取得する正しい方法が何であるのだろうか。スウィフト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

私はそのより一貫性のため、最初の例のために行くだろう。

将来、複数のコンポーネントを使用することに決めた場合でも、コードは同じままです。

関連する問題