TextField输入完成后关闭键盘

输入完成后按下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关联。
 
如果是数字键盘,没有Done键怎么办呢,可以通过触摸背景关闭键盘

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

 

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

你可能感兴趣的:(textfield)