0

I know that I can resign a single text field to first responder when touching a button by implementing the following:

- (IBAction)signMeUpButton:(id)sender {


     [self.textfield resignFirstResponder];
}

However, In my case I have multiple text fields, and I feel like typing them in one at a time, cant possibly be the best way / most modern way of doing so.

I reviewed multiple questions on the site, such as this one:

iOS SDK: Dismiss keyboard when a button gets clicked?

But none of them mention, having more than one text field and dismissing them with an IBAction ... What can I do in this situation?

Community
  • 1
  • 1
iBull
  • 65
  • 5

3 Answers3

1

You may try this:

- (IBAction)signMeUpButton:(id)sender
{
     [self.view endEditing:YES];
}
klcjr89
  • 5,662
  • 9
  • 54
  • 91
1

If you have more than one text field, it's best to implement the following

[self.view endEditing:YES];

So, in your case it would be :

    - (IBAction) signMeUpButton:(id)sender {
      [self.view endEditing:YES];
      }

That will do exactly what you are looking for!

vzm
  • 2,380
  • 4
  • 25
  • 45
0

try this

UITextField *currentTextField;


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

-(IBAction)click:(id)sender
{
      [currentTextField resignFirstResponder];
}
falcon143
  • 684
  • 4
  • 19
  • try this if([textField isFirstResponder]){ [textField resignFirstResponder]; } or [[self view] endEditing:YES]; – falcon143 Jul 15 '14 at 04:23
  • I think this solution better http://stackoverflow.com/questions/5029267/is-there-any-way-of-asking-an-ios-view-which-of-its-children-has-first-responder/14135456#14135456 – Huy Nghia Jul 15 '14 at 04:24