简体   繁体   English

第一次点击时显示的键盘是UITextField.inputView = UIPickerView

[英]Keyboard is showing on first tap for a UITextField.inputView = UIPickerView

I couldn't find nothing respect to Swift about this matter. 在这件事上,我找不到任何对Swift的尊重。

I'm configuring a UIPickerView as inputView for a UITextField . 我正在将UIPickerView配置为UITextField inputView

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. 一切正常,但是当我在第一时间点击此特定的UITextField时,显示的是键盘,而不是UIPickerView ,如果再次单击它,则显示UIPickerView

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: 确保您正在设置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

to viewDidLoad 查看DidLoad

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM