uitableviewuitextfielduikeyboard

How do I make the keyboard go away when the user clicks somewhere else?


Possible Duplicate:
Dismiss keyboard by touching background of UITableView

How do I make the keyboard go away when the user clicks somewhere else?

Note: I know how to make the keyboard disappear with sending the resignFirstResponder command to the UITextField. At present the "Done" button is connected to all the correct code to do this and this works.

I have a UITableView with different UITableViewCells, and if the user moves onto another cell I want the keyboard to disappear.

So what events do I also need to include the resignFirstResponder in, for the keyboard to disappear.

Suppose UITableViewCell A has the UITextField, and UITableViewCell B has a button. If the user presses the button in cell B, then I will need to send the command resignFirstResponder back to the UITextField in cell A. First of all the button has no idea which cell it should sent the command to, and second even if the button did know which cell to send the command to how would it?


Solution

  • There's no trivial way to do this. You can put a transparent set of "shield views" all the way around the text field that take up the rest of the screen, and use any touches on them to dismiss the keyboard.