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
xcode swift view keyboard picker


source to share


3 answers


You just need to call:

self.view.endEditing(true)

      



This will resign pickerView.

+3


source to share


The problem may be that you are resigning the first respondent. Also, I believe you do not need to set the textbox as the first responder, as it becomes the first responder when you click on it to edit.



0


source to share


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







All Articles
Loading...
X
Show
Funny
Dev
Pics