Search code examples
swiftuipickerviewdelegation

How to get current value of UIPickerView AFTER it has already been selected


Call me stupid, but I just cannot figure out how you can get the current value of a UIPickerView after it has already been selected. There are plenty of SO Q&As on getting it if it's just been changed by using the delegate's didSelectRowAt method, but what if it's already been set a while ago? You can't manually call this delegate method... can you?

I know this is probably an easy one, but your help is appreciated.


Solution

  • UIPickerView has a selectedRow that will return the currently selected row:

    https://developer.apple.com/documentation/uikit/uipickerview/1614369-selectedrow

    let selected = myPicker.selectedRow(inComponent: 0) //gets the selection in the first component of the picker