TextField输入完成后关闭键盘

来源:互联网 发布:c语言1到n求和 编辑:程序博客网 时间:2024/04/26 07:43

http://2015.iteye.com/blog/1113780

输入完成后按下Done键关闭键盘

 

在Interface Builder中选择TextField,然后在Text Field Attributes中找到Text Input Traits,选择Return Key为Done。

//按下Done键关闭键盘  - (IBAction) textFieldDoneEditing:(id)sender {      [sender resignFirstResponder];  }  

找到事件Did End On Exit,与textFieldDoneEditing关联。完成输入后点击return键盘
 下边storyboard还未用过,待用
如果是数字键盘,没有Done键怎么办呢,可以通过触摸背景关闭键盘

//通过触摸背景关闭键盘  - (IBAction) backgroundTap:(id)sender  {      [nameField resignFirstResponder];      [numberField resignFirstResponder];  } 

选择背景的Touch Down事件,关联backgroundTap。