Search code examples
iosswiftuipickerview

Send button, which opens UIPickerView to UIPickerView's selectRow function


I have two buttons, which opens one UIPickerView

@IBOutlet weak var convertFromButton: UIButton!
@IBOutlet weak var convertToButton: UIButton!

I need picker's selectRow function to know, which button user press to open it and to change title of this button. So, I need function like this, but I don't know how to send button to this function.

func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int, button: UIButton) {
    button.setTitle(converter.convertTypes[row], forState: UIControlState.Normal)
    typePicker.hidden = true;
}

Or do I need separate picker for each button?


Solution

  • You can use additional variable to store the latest sender button which was used to open a picker and check its value in the pickerView:didSelectRow: