title: hide the keyboard when touched outside for tableView
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/11274119/dismiss-keyboard-on-touch-anywhere-outside-uitextfield">Dismiss keyboard on touch anywhere outside UITextField</a>  </p>
  </blockquote>
  
  
  
  <p>MyViewController in interface builder :</p>
  
  <p><img src="https://i.stack.imgur.com/4joIz.png" alt="enter image description here"></p>
  
  <p>In my custom TableViewCell I have a TextField. <code>My plan is disappear KeyPad when User Clicks outside the touchpad.</code></p>
  
  <p>I could not make it works using <code>UITapGestureRecognizer</code></p>
  
  <p>in viewDidLoad:</p>
  
  <pre><code>UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
  [self.tableView addGestureRecognizer:gestureRecognizer];
  </code></pre>
  
  <p>Then how should I make it work with <code>cell.TextField</code> ?</p>
  
  <p>I read about this solution <a href="https://stackoverflow.com/questions/2321038/dismiss-keyboard-by-touching-background-of-uitableview">here</a>:</p>
  
  <pre><code>[self.view endEditing:YES];
  </code></pre>
  
  <p>or </p>
  
  <pre><code>[[self.tableView superView] endEditing];
  </code></pre>
  
  <p>I couldn't make it work neither. Where should I use them?</p>
  
  <p>Or if you have any better way, please let me know.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I could not make it work:</p>
  
  <pre><code>@property (nonatomic, strong) UITextField *cellTextField;
  </code></pre>
  
  <p>in viewDidLoad:</p>
  
  <pre><code>UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
      [self.settingTableView addGestureRecognizer:gestureRecognizer];
  </code></pre>
  
  <p>And we have:</p>
  
  <pre><code>- (void) hideKeyboard {
      [self.cellTextField resignFirstResponder];
  }
  </code></pre>
  
  <p>And :</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {
      static NSString *CellIdentifier = @"Cell";
      SettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  
  
      self.cellTextField = cell.dataEdit;
  </code></pre>
  
  <p>What is my fault?</p>