Search code examples
iosswiftdelegatesuipickerview

Get selected value from UIPickerView custom delegate & data source


So I cannot provide you with any code, but it's quite simple what I want to achieve. I am searching for a way to get the selected value from an UIPickerView in iOS 8 (Swift) these pickerviews have a custom delegate & data source.

So the method of didSelectRow is accessed in a custom class, not the ViewController, but I would have to be able to get the selected value and use it in the ViewController. Let's say, place it in a textbox.

I can't find a way to do this, should I try to access the delegate itself or what should I be doing?

Care to share your knowledge with the students of Application Development? :)


Solution

  • The UIPickerView class has a method named: `selectedRowInComponent'. This function may help you select components in a picker view. Apple Documentation for UIPickerView class would help you with your project.

    Also make sure your view controller conforms to the UIPickerViewController Delegate and Data source.