title: Dismissing keyboard from UISearchBar when the X button is tapped
body: <p>I'm using the UISearchBar (but not the SearchDisplayController that's typically used in conjunction) and I'd like to dismiss the keyboard when you hit the 'X' button.</p>
  
  <p>I've followed <a href="https://stackoverflow.com/questions/4120605/uisearchbar-and-event-fired-when-x-element-is-tapped">TomSwift's suggestion</a> on getting called when the 'X' is tapped and that works great. But resigning first responder from the text field and also invoking in the UISearchBar instance, both with <code>resignFirstResponder</code>, won't make the keyboard go away. </p>
  
  <p>Is there a way to get rid of the keyboard when the user has tapped the X button? </p>
  
  <p>Here's what I did to get the 'Clear' notify:</p>
  
  <pre><code>- (void)viewDidLoad:
  {
      for (UIView* v in searchBar.subviews)
      {
          if ( [v isKindOfClass: [UITextField class]] )
          {
              UITextField *tf = (UITextField *)v;
              tf.delegate = self;
              break;
          }
      }    
  }
  </code></pre>
  
  <p>Then I have my class setup to implement both UISearchBarDelegate and UITextFieldDelegate.</p>
  
  <p>Having the class serve as the textfield delegate allows me to get this call:</p>
  
  <pre><code>- (BOOL)textFieldShouldClear:(UITextField *)textField
  {
       [textField resignFirstResponder];
       [self.searchBar resignFirstResponder];
       return YES;
  }
  </code></pre>
  
  <p>I've tried everything I can think of. The last thing I'm trying is to find a way to issue the 'searchBarCancelButtonClicked' that UISearchDelegate will invoke on my Controller class but not I'm sure how I could do this since the UISearchBar doesn't seem to have any direct methods to invoke with this name.</p>