hide keyboard for text field in swift programming language

I think the Problem is with setting the Delegate.

Please set textfield Delegate to your ViewController like this

class ViewController: UIViewController,UITextFieldDelegate {

and then create the IBOutlet for your text field like this

@IBOutlet var txtTest : UITextField = nil

make sure that it is connected to your text field on your view in storyboard.

finally set its Delegate using

txtTest.delegate=self

We are almost done. Now place this delegate function into your class.

func textFieldShouldReturn(textField: UITextField!) -> Bool // called when 'return' key pressed. return NO to ignore.
    {
        textField.resignFirstResponder()
        return true;
    }

Hope this will solve your issue.

Leave a Comment