This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
2
UIPickerView not firing didSelectRow
Post Body
Hi all. I'm creating my first picker menu. The idea of my code is the UIPickerView replaces the keyboard (inputView). However when I run my code on simulator, selecting the picker, and then clicking off the text field, the text box stays empty. Is there something I'm missing? From all the examples online I found, there is no need for a 'done' button to confirm. Or is there just something wrong with my Xcode/Simulator? I'm running MacOS 10.14 on VMWare.
Below is my code:
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
@IBOutlet weak var sportSelector: UITextField!
@IBOutlet weak var sportTitle: UITextField!
//@IBOutlet weak var sportList: UIPickerView!
//var sports: [String] = [String]()
let sports = ["Climbing", "Hockey"]
let sportList = UIPickerView()
override func viewDidLoad() {
super.viewDidLoad()
sportSelector.inputView = sportList
//Connect Data
self.sportList.delegate = self
self.sportList.dataSource = self
// Do any additional setup after loading the view.
}
//Number of columns in picker view
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
//Number of items in picker view
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return sports.count
}
//Items in picker view
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?{
return sports[row]
}
//Capture the picker view selection
func pickerView(_pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
sportSelector.text = sports[row]
}
}
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 5 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/swift/comme...