第一次点击 UITextField.inputView = UIPickerView 时会显示键盘
Keyboard is showing on first tap for a UITextField.inputView = UIPickerView
关于这件事,我找不到任何关于 Swift 的内容。
我正在将 UIPickerView
配置为 inputView
用于 UITextField
。
一切正常,但是当我第一次点击这个特定的 UITextField
时,显示的是键盘,而不是 UIPickerView
,如果我再次点击它,[=显示 12=]。
有人知道我做错了什么吗?
查看我的部分代码。
@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]
}
确保您正在设置 UITextFieldDelegate,然后我也会移动所有这些:
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
查看DidLoad
关于这件事,我找不到任何关于 Swift 的内容。
我正在将 UIPickerView
配置为 inputView
用于 UITextField
。
一切正常,但是当我第一次点击这个特定的 UITextField
时,显示的是键盘,而不是 UIPickerView
,如果我再次点击它,[=显示 12=]。
有人知道我做错了什么吗?
查看我的部分代码。
@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]
}
确保您正在设置 UITextFieldDelegate,然后我也会移动所有这些:
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
查看DidLoad