iOS开发收回键盘

iOS开发中,需要用户在按Return或者Done之后能够收回键盘

方法是先设置UITextField Delegate,并实现 textFieldShouldReturn 方法,返回true

先在storyboard中把TextField和ViewController相连,选择delegate

 然后ViewController的.h文件中加入<UITextFieldDelegate>

@interface FHWViewControllerMain : UIViewController <UITextFieldDelegate>

实现 textFieldShouldReturn 方法

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
    [theTextField resignFirstResponder];
    return true;
}
原文地址:https://www.cnblogs.com/fatlyz/p/2545696.html