[swift]键盘在第一个tap上显示为 UITextField.inputView = UIPickerView

标签: UITextView ios Swift
发布时间: 2016/5/8 0:43:10
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我找不到什么尊重到 Swift 这件事。

我配置的 UIPickerView 作为 inputViewUITextField

一切工作正常,但当我点击此特定 UITextField 在第一次,键盘显示了,不 UIPickerView ,如果再次点击它 UIPickerView 显示。

谁知道在做什么错了吗?

看看我的代码的一些部分。

@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]
}

解决方法 1:

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

对 viewDidLoad

官方微信
官方QQ群
31647020