Getting selected value of a UIPickerViewControl in Swift

后端 未结 4 1182
后悔当初
后悔当初 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 03:43

    you will have to set the picker view delegate to self and override this function

    func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
       {
            // use the row to get the selected row from the picker view
            // using the row extract the value from your datasource (array[row])
        }
    

    or

    you can use this to extract as per your usage

    var selectedValue = pickerViewContent[pickerView.selectedRowInComponent(0)]
    

    where pickerViewContent is your array of dataSource

提交回复
热议问题