views:

9750

answers:

3

normally when you touch the text input area, the keyboard pops up and when you touch the empty area of screen, the keyboard disappeared. How to make that happen?

just like what we experienced on iphone safari...

Thank you

+3  A: 

Send resignFirstResponder to the control.

Chris Lundie
+13  A: 

Here's a step by step for it:

Add an IBAction to your view controller, such as - (IBAction)backgroundTouch:(id)sender

In the backgroundTouch action, you need to send the resignFirstResponder message to all of the text boxes in your view. This is unfortunate but necessary since there's currently no way to retrieve the object that currently has FirstResponder status. It should look something like this:

- (IBAction)backgroundTouch:(id)sender {
  [someTextBox resignFirstResponder];
  [anotherTextBox resignFirstResponder];
}

Add a button control to the view, size it to cover the entire visible area (except for the status bar or any tab or navigation controllers). Select the button and then go to the Layout Menu and select Send To Back. Also set the button's Type to custom, which is invisible if you don't specifically supply any drawing code for it.

Connect the Button's Touch Up Inside event to the backgroundTouch: action and try it out.

HitScan
Thank you...let me have a try
many thx ... it works
Short cut found on another post: [self.view endEditing:YES]; will end editing in all subviews and resign first responder. Its a lot more clear than enumerating all of your text boxes and won't break when you add fields later!
Peter DeWeese
+3  A: 

there's a tutorial about that problem (also concerning the numerical keyboard with no DONE key) over here