hide keyboard for text field in swift programming language

后端 未结 14 1065
不思量自难忘°
不思量自难忘° 2020-11-27 17:07

I have little experience in Objective-C. I want to hide the keyboard for a text field using the Swift programming language.

I also tried this

func te         


        
14条回答
  •  [愿得一人]
    2020-11-27 17:55

    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.

提交回复
热议问题