tags:

views:

532

answers:

2

Problem: If you have a big form with a lot of text input fields with number pad, you would not want to tell every single text field something like

[myTextField1 resignFirstResponder];
[myTextField2 resignFirstResponder];

instead, it would be great to just tell for example an invisible background button, that it is the First Responder as soon as the user tabs outside of any text field.

Like in JavaScript, when you give an element the focus(), all others lose it. How can I do that in UIKit?

+4  A: 
[button becomeFirstResponder];
Can Berk Güder
A: 
  1. In your header file, paste this: -(IBAction)backgroundClicked:(id)sender;
  2. in your implementation file, paste this:

    • (IBAction) backgroundClicked:(id)sender { [nameField resignFirstResponder]; [numberField resignFirstResponder]; }
  3. In InterfaceBuilder, create a button that covers the entire view.

  4. with the button selected, click Layout > Send to Back
  5. Control drag from the button to File's Owner and select the outlet called: backgroundClicked.

[:

Jevarlo