不能按返回键隐藏键盘

我的代码如下:

.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];
}

在.h类中设置:

你的
ViewController : UIViewController

然后在创建TextField的地方delegat:

 myTextField.delegate = self;

最后,

-(BOOL) textFieldShouldReturn:(UITextField *)textField{
     [textField resignFirstResponder];
     return YES;
  }

默认执行影响UIModalPresentationFormSheet的可见性,因此为了隐藏键盘要重写:

  - (BOOL)disablesAutomaticKeyboardDismissal 
 {
   return NO; 
 }

使用UITextField中的Delegate:

-(IBAction)hideKeyboard:(id)sender
{
    [your_textfield resignFirstResponder]; 
}