今天写表单,用了许多的textfield 不过中间点其他按钮需要关闭当前的键盘(当你不知道是那个 textfield 正在编辑状态的时候),看了textfield的属性没找到一个合适的。
于是在网上找了下,发现view中有个方法可以解决多个textfield情况下,关闭键盘(当然textview也适用)
该方法为UIView中的一个方法,定义为
1 | - ( BOOL )endEditing:( BOOL )force |
Causes the view (or one of its embedded text fields) to resign the first responder status.
This method looks at the current view and its subview hierarchy for the text field that is currently the first responder. If it finds one, it asks that text field to resign as first responder. If the force parameter is set to YES, the text field is never even asked; it is forced to resign.意为:
注销当前view(或它下属嵌入的text fields)的first responder 状态。
该方法会在当前view以及其subview层次结构中需找当前处于first responder状态的text field。如果找到的话会注销其first responder状态,如果指定force参数为YES,则不再询问text field,而直接强制注销其first responder状态。
好了,有了这个快捷方法,我们 只要调用
1 | [self.view endEditing:YES]; |