0

I am really new to swift, I have tried to find my question on the internet but all solutions did not work for me.

I have got an script that populates a picker, and what I would like to do now is to get the selected value of this picker and pass it to my other view. Any ideas of how to do it?

My picker script:

class SpecViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

@IBOutlet var picker: UIPickerView!

var pickerData: [String] = [String]()

override func viewDidLoad() {
    super.viewDidLoad()

    self.picker.delegate = self
    self.picker.dataSource = self

    pickerData = ["Medicina", "Marketing", "Técnico"]    }

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

// The number of columns of data
func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}

// The number of rows of data
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return pickerData.count
}

// The data to return for the row and component (column) that's being passed in
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    return pickerData[row]
}

Thank you for your time.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
alberzyzz
  • 277
  • 2
  • 15

0 Answers0