Search code examples
iphoneiosuisearchbaruisearchdisplaycontroller

UISearchDisplayController - Clicking overlay, method called?


Is there a delegate method that gets called when a user clicks on the dark overlay, which basically removes first responder status from the UISearchDisplayController? (I cannot find one in the docs.)

I would like to know when users click the black overlay, and the keyboard is hidden.


Solution

  • If you implement the UISearchDisplayDelegate then:

    - (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
    

    should be called upon tapping the overlay.

    I messed around with this components a few months back but ended up not using it because you can not change its standard behavior much.

    What I did found out is that it is just a wrapper for the UISearchBar, so you can access the searchBar on your SearchDisplayController like this:

    [searchDisplayController.searchBar setDelegate:self];
    

    This way gives you a bit more freedom to access the delegate methods of the searchBar component itself. Like textDidChange, cancelButtonClicked etc.