var Months = ["A","B","C","D"]
var pickerview = UIPickerView()
@IBOutlet var txt_Month: UITextField!

override func viewDidLoad() {
    super.viewDidLoad()

    pickerview.isHidden = true
    pickerview.dataSource = self
    pickerview.delegate =  self

    txt_Month.inputView = pickerview
} 

func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return 1
}

func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return Months.count
}

func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
   txt_Month.text = Months[row]
}

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{
    return Months[row]
}

2 Answers

1
Alastar On

maybe it's because pickerview is hidden?

0
Bhavisha Khatri On

Set the pickerview is unhide.

pickerview.isHidden = false