2015-11-10 50 views
0

我無法找到關於這件事Swift的任何方面。鍵盤在第一次點擊時顯示爲UITextField.inputView = UIPickerView

對於UITextField,我將UIPickerView配置爲inputView

一切工作正常,但是當我點擊這個特定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] 
} 
+0

你有UITextFieldDelegate設置? –

+0

我是新手,你能解釋我該怎麼做? –

回答

0

確保你設置你的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中

+1

這就是它!我把它放在'IBAction'裏面,非常感謝你的幫助,它的工作非常完美。 –

+0

太棒了!很高興我可以得到一些幫助! :) –

相關問題