开发者社区 问答 正文

不能按返回键隐藏键盘

我的代码如下:

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

但是按返回键的时候,还是不能隐藏键盘啊

展开
收起
爵霸 2016-05-27 11:48:05 1860 分享 版权
1 条回答
写回答
取消 提交回答
  •     [self. aTextField resignFirstResponder];
        [self  aaaa];
    }
    -(void)aaaa{
       你要返回按钮做的事情;
    }

    或者是

    -(IBAction)hideKeyboard:(id)sender{
        [self  aaaa];
    
    
        你返回按钮要做的事情;
    
    }
    -(void)aaaa{
       [self. aTextField resignFirstResponder];
    }
    2019-07-17 19:17:36
    赞同 展开评论
问答地址: