Quantcast
Channel: Active questions tagged uipickerview - Stack Overflow
Viewing all articles
Browse latest Browse all 592

Set default value of UIPickerView when UITextField is touched

$
0
0

I want to keep the same placeholder text in my UITextField which is "Location". Once the UITextField is touched then I want the first value of the UIPickerView to be displayed. The way it is now the user has to scroll down then back up for the value to be displayed in the UITextField. I want the value to be displayed in the UITextField as soon as the UIPickerView is open. unselected,selected-UITextField still shows no value

override func viewDidLoad() {    let thePicker = UIPickerView()    thePicker.delegate = self    location.inputView = thePicker    thePicker.selectRow(1, inComponent: 0, animated: true)}func numberOfComponents(in pickerView: UIPickerView) -> Int {    return 1}func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {    return pickOptions.count}func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {    return pickOptions[row]}func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {    location.text = pickOptions[row]}

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>