首先.h中声明关闭虚拟键盘方法-(IBAction)closeKeyBoard:(id)sender;
.m中实现:
方法一:拖一个Button到view中,并将它铺满整屏,设置按钮样式为Custom,即无外观。连接button的touch up inside方法即可。
-(void)closeKeyBoard:(id)sender
{
[textFieldName resignFirstResponder];
}
方法二:在主view的identity inspector中将custom class改为UIcontrol,这样就能够触发操作方法。实现方法同一,然后连接view的touch up inside方法即可。
方法三:当textfield很多时,使用此方法可以不用一个个遍历输入框。
-(void)closeKeyBoard:(id)sender
{
[self.view endEditing:YES];
}