Getting selected value of a UIPickerViewControl in Swift

后端 未结 4 1223
后悔当初
后悔当初 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:39

    All the answers so far presuppose you can easily connect the selected row back to the original data array. The solution is fairly easy if you can do that, but the question specifically addresses the case where the original array is not readily available. For instance I have 3 pickers in table cells that expand when one row is tapped, and they show 3 different arrays.

    It would save me a lot of trouble if I could simply retrieve the selected text from the picker itself, perhaps in the code for my custom cell, instead of having to figure out which picker, which data array, which row and so on.

    If the answer is that you can't, that's OK, I'll sort it all out. But the question is whether there's a shortcut.

提交回复
热议问题