在我的课堂上,我有超过30个UITextField和一个UIButton。当我点击uibutton时,我需要重新签名所有uitextfield的键盘而不给所有30个uitextfields提供resignfirstresponder。
我的代码就像这样
-(IBAction)click:(id)sender
{
[txt1 resignFirstResponder];
[txt2 resignFirstResponder];
[txt3 resignFirstResponder];
[txt4 resignFirstResponder];
.
.
.
[txt30 resignFirstResponder];
}
我需要简单的方法来重新签名UITextField键盘
答案 0 :(得分:7)
每个视图都有endEditing属性,请尝试这个
[[self view] endEditing:YES];
让我知道它是否适合您..
答案 1 :(得分:3)
UITextField *currentTextField;
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
currentTextField = textField;
}
-(IBAction)click:(id)sender
{
[currentTextField resignFirstResponder];
}
答案 2 :(得分:0)
然后只需在下面的方法中添加
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[textField resignFirstResponder];
return YES;
}
或
在委托方法
中-(void)textFieldDidEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
}
答案 3 :(得分:0)
-(void)KeyboardHide
{
[txt1 resignFirstResponder];
....
....
[txt30 resignFirstResponder];
}
-(IBAction)click:(id)sender
{
[Self KeyboardHide];
}