我的代碼如下:
.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;
}
但是按返回鍵的時候,還是不能隱藏鍵盤啊
-(IBAction)hideKeyboard:(id)sender{
[self. aTextField resignFirstResponder];
[self aaaa];
}
-(void)aaaa{
你要返回按鈕做的事情;
}
或者是
-(IBAction)hideKeyboard:(id)sender{
[self aaaa];
你返回按鈕要做的事情;
}
-(void)aaaa{
[self. aTextField resignFirstResponder];
}