I tried it with the resignFirstResponder, but the keyboard doesn´t hide.
I´m typing in an other textfield and want to hide the keyboard, when i go into the textfield for the pickerview.
Otherwise the keyboard is hiding my pickerview.
Maybe the code will help.
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UITextFieldDelegate {
@IBOutlet weak var pickerTF: UITextField!
@IBOutlet weak var pickerPV: UIPickerView!
@IBOutlet weak var keyboardTestTF: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
var test = ["1", "2", "3"]
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return test.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return test[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
self.pickerTF.text = self.test[row]
self.pickerPV.isHidden = true
}
func textFieldDidBeginEditing(_ textField: UITextField) {
if textField == self.pickerTF {
self.pickerPV.isHidden = false
textField.endEditing(true)
}
}
//Action for the textfield for typing with the Keyboard
@IBAction func hideKeyboardFromTF(_ sender: UITextField) {
sender.resignFirstResponder()
}
}