Thangavel
Thangavel

Reputation: 173

More then one UITextField keyboard dismiss on UIButton Click in iOS

In my class,i have more then 30 UITextField and one UIButton. When I click the uibutton i need to resign the keyboard of all uitextfield without giving resignfirstresponder to all 30 uitextfields.

My code like this

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

I need simple way to resign UITextField keyboard

Upvotes: 0

Views: 1300

Answers (4)

iCoder
iCoder

Reputation: 1318

Every view has endEditing property , try simply this

 [[self view] endEditing:YES];

and let me know whether it works for you or not ..

Upvotes: 7

Bhavesh Nayi
Bhavesh Nayi

Reputation: 3656

-(void)KeyboardHide
{
    [txt1 resignFirstResponder];
    ....
    ....
    [txt30 resignFirstResponder];
}


-(IBAction)click:(id)sender
{
    [Self KeyboardHide];
}

Upvotes: 0

Manu
Manu

Reputation: 4750

UITextField *currentTextField;


- (void)textFieldDidBeginEditing:(UITextField *)textField
{
      currentTextField = textField;
}

-(IBAction)click:(id)sender
{
      [currentTextField resignFirstResponder];
}

Upvotes: 3

IronManGill
IronManGill

Reputation: 7226

Then simply in the method below add

 - (BOOL)textFieldShouldReturn:(UITextField *)textField 
{
      [textField resignFirstResponder];
      return YES;
}

or

in the delegate method

-(void)textFieldDidEndEditing:(UITextField *)textField 
{
    [textField resignFirstResponder];
}

Upvotes: 0

Related Questions