编辑 UITextField 时如何关闭键盘 [英] How do you dismiss the keyboard when editing a UITextField

查看:34
本文介绍了编辑 UITextField 时如何关闭键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道当我想关闭键盘时,我需要告诉我的 UITextField 退出第一响应者,但我不确定如何知道用户何时按下了键盘上的完成"键.有我可以关注的通知吗?

I know that I need to tell my UITextField to resign first responder when I want to dismis the keyboard, but I'm not sure how to know when the user has pressed the "Done" key on the keyboard. Is there a notification I can watch for?

推荐答案

我将 UITextField 的委托设置为我的 ViewController 类.

I set the delegate of the UITextField to my ViewController class.

在那个类中我实现了这个方法如下:

In that class I implemented this method as following:

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

这篇关于编辑 UITextField 时如何关闭键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆