Search code examples
iosswiftuipickerview

How to retrieve data/values from UIPickerView (IOS using Swift)?


How do i retrieve/get data/values from UIPickerView when the user have selected from the many choices?

var view1 = 0
var view2 = 0
var view3 = 0

let pickerData = [["1", "2"], ["1", "2"], ["1", "2"]]
label.text = "\(view1):\(view2):\(view3)"

So if the user choose 1,1,2 the label would show "1:1:2". How would what the user be inserted into the tree different views be done?

Here is the full code if that helps. Link


Solution

  • You can use pickerView.selectedRowInComponent:

    print(pickerData[0][pickerView.selectedRowInComponent(0)],
            pickerData[1][pickerView.selectedRowInComponent(1)],
            pickerData[2][pickerView.selectedRowInComponent(2)])