I couldn't find nothing respect to Swift about this matter.
I'm configuring a UIPickerView
as inputView
for a UITextField
.
Everything is working fine, but when I tap on this specific UITextField
at the fisrt time, the keyboard is showing, not the UIPickerView
, if I click on it again, the UIPickerView
is showed.
Anyone know what am I doing wrong?
See some parts of my code.
@IBAction func textFieldEditingMot(sender: UITextField) {
let motivoPicker: UIPickerView = UIPickerView()
motivos = ["Pedido de demissão","Dispensa sem justa causa","Dispensa com justa causa", "Término do contrato de experiência"]
motivoPicker.delegate = self
motivoPicker.dataSource = self
motivoTextField.inputView = motivoPicker
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int
{
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int
{
return motivos.count
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)
{
motivoTextField.text = motivos[row]
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
{
return motivos[row]
}
Make sure that you are setting your UITextFieldDelegate, and then I would also move all of this:
let motivoPicker: UIPickerView = UIPickerView()
motivos = ["Pedido de demissão","Dispensa sem justa causa","Dispensa com justa causa", "Término do contrato de experiência"]
motivoPicker.delegate = self
motivoPicker.dataSource = self
motivoTextField.inputView = motivoPicker
to viewDidLoad