我的代码如下:
.h文件中:
@interface TouchLabelViewController : UIViewController<UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UITextField *aTextField;
-(IBAction)hideKeyboard:(id)sender;
.m文件:
-(IBAction)hideKeyboard:(id)sender{
[(UITextField*)sender resignFirstResponder];
}
后来我还尝试了
.h文件:
- (void)viewDidLoad
{
[super viewDidLoad];
aTextField.delegate = self;
}
@property (strong, nonatomic) IBOutlet UITextField *aTextField;
-(BOOL) textFieldShouldReturn:(UITextField *)textField;
.m文件
-(BOOL) textFieldShouldReturn:(UITextField *)textField{
[aTextField resignFirstResponder];
return YES;
}
但是按返回键的时候,还是不能隐藏键盘啊