How do I dismiss the iOS keyboard?

后端 未结 16 1143
情书的邮戳
情书的邮戳 2020-11-29 20:00

I have a UITextfield that i\'d like to dismiss the keyboard for. I can\'t seem to make the keyboard go away no matter what code i use.

16条回答
  •  生来不讨喜
    2020-11-29 20:08

    In your view controller YourViewController.h file, make sure you implement UITextFieldDelegate protocol :

    @interface YourViewController : 
    
    @end
    

    Then, in YourViewController.m file, implement the following instance method:

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        [self.yourTextField1 resignFirstResponder];
        [self.yourTextField2 resignFirstResponder];
        ...
        [self.yourTextFieldn resignFirstResponder];
    }
    

提交回复
热议问题