0

I'm developing an app that has an UITableViewController with static cells. Those static cells are custom ones and have UITextFields within them. If the user touches one of those textfields, the keyboard pops up. So, after that, what I need to do is to be able to dismiss the keyboard by touching anything on the background. By anything I mean the table view background, its cells and the content of those cells (like the text fields for example).

I used to do this by placing a View in the front of all my other subviews and capture the Touch Inside Up event to dismiss the keyboard. Unfortunately, I can't do this this time because I'm using a UITableViewController and I can't switch it back to an UIViewController because I've already done a lot of work with those static cells.

Dan J
  • 16,319
  • 7
  • 50
  • 82
Alex Takashi Tanabe
  • 129
  • 1
  • 3
  • 11

2 Answers2

1
 -(void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event{
    
[yourTextField resignFirstResponder];
 }

Try that.

EDIT

Hi,

I've got your answer :

-(BOOL)isFirstResponder

When you enter something in a text field, it becomes first responder and the keyboard appears. You know that the keyboard is active if [textField isFirstReponder] returns YES.

You may also see that link.may be it will help you.

how to hide the keyboard when empty area is touched on iphone

Community
  • 1
  • 1
Emon
  • 958
  • 3
  • 10
  • 28
  • It works just when I touch one cell... but what I need is to dismiss the Keyboard when the user touches the background of the tableview, its cells or any other subview it touches (including others textviews). – Alex Takashi Tanabe Jan 05 '12 at 19:13
0

Well, I found the answer myself. What I need to do was just place programatically an UIView in the foreground and do as I said in the original post. I couldn't do this before because I was trying to achieve that from the Interface Builder.

Alex Takashi Tanabe
  • 129
  • 1
  • 3
  • 11