在UIButton上有多个UITextField键盘关闭点击iOS

时间:2013-06-18 07:25:55

标签: ios objective-c uitextfield

在我的课堂上,我有超过30个UITextField和一个UIButton。当我点击uibutton时,我需要重新签名所有uitextfield的键盘而不给所有30个uitextfields提供resignfirstresponder。

我的代码就像这样

-(IBAction)click:(id)sender
{
   [txt1 resignFirstResponder];
   [txt2 resignFirstResponder];
   [txt3 resignFirstResponder];
   [txt4 resignFirstResponder];
   .
   .
   .
   [txt30 resignFirstResponder];
 }

我需要简单的方法来重新签名UITextField键盘

4 个答案:

答案 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];
}