Getting selected value of a UIPickerViewControl in Swift

后端 未结 4 1174
后悔当初
后悔当初 2021-02-05 03:05

How can I get the selected value of a UIPickerViewControl in Swift?

I tried something like this:

labelTest.text = Spinner1.selectedRowInComponent(0).desc         


        
4条回答
  •  不思量自难忘°
    2021-02-05 04:05

    Swift 4

    let selectedYearPicker = pickerData[yearPicker.selectedRow(inComponent: 
    print(selectedYearPicker)
    

    Or

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent  component: Int) {
        let yearValueSelected = pickerData[row] as String
        print(yearValueSelected)
    }
    

提交回复
热议问题