title: Can I hook into UISearchBar's Clear Button?
body: <p>I've got a UISearchBar in my interface and I want to customise the behaviour of the the small clear button that appears in the search bar after some text has been entered (it's a small grey circle with a cross in it, appears on the right side of the search field).</p>
  
  <p>Basically, I want it to not only clear the text of the search bar (which is the default implementation) but to also clear some other stuff from my interface, but calling one of my own methods.</p>
  
  <p>I can't find anything in the docs for the UISearchBar class or the UISearchBarDelegate protocol - it doesn't look like you can directly get access to this behaviour.</p>
  
  <p>The one thing I did note was that the docs explained that the delegate method:</p>
  
  <pre><code>- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText;
  </code></pre>
  
  <p>is called after the clear button is tapped.</p>
  
  <p>I initially wrote some code in that method that checked the search bar's text property, and if it was empty, then it had been cleared and to do all my other stuff.</p>
  
  <p>Two problems which this though:</p>
  
  <p>Firstly, for some reason I cannot fathom, even though I tell the search bar to resignFirstResponder at the end of my method, something, somewhere is setting it back to becomeFirstResponder. Really annoying...</p>
  
  <p>Secondly, if the user doesn't use the clear button, and simply deletes the text in the bar using the delete button on the keyboard, this method is fired off and their search results go away. Not good.</p>
  
  <p>Any advice or pointers in the right direction would be great!</p>
  
  <p>Thanks!</p>