How to retire
I am using Xcode 6 and Swift. I have textboxes and I assigned them to attributes inputView
for collector views that I created as suchvar examplePickerView : UIPickerView = UIPickerView()
This causes the selection view to be displayed instead of the normal keyboard (s) when the text screen is pressed for editing. The problem is it textField.resignFirstResponder()
doesn't reset the selection view the way it would with regular keyboards. I've tried assigning the view to picker as the first attribute of the responder, but no luck.
+3
source to share
3 answers
you have to use UITextFieldDelegate protocol
Example:
class ViewController: UIViewController, UITextFieldDelegate {
var textField : UITextField!
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
override func viewDidLoad() {
super.viewDidLoad()
textField = UITextField(frame: CGRect(x: 0, y: 0, width: view.bounds.width - 100, height: 50))
textField.delegate = self
view.addSubview(textField)
}
0
source to share