Search code examples
iosuisearchbaruisearchdisplaycontroller

What is the exact use of UISearchDisplayController?


Could anyone simply explain the need for UISearchDisplayController? I actually implemented UISearchBar alone in my class and used a table view to show the results. It just works fine.

I made an empty view. It will be shown in case of no results found with search words. Also, for each press in search bar, I reloaded the tableview, so that the results continuously changing with respect to the typed word.

I used these methods to do this.

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
- (void) searchBarCancelButtonClicked:(UISearchBar *)searchBar
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar

Here is my doubts:

  • Apart from this things, why should one implement UISearchDisplayController? What is the use of it?
  • Should I reload the table view each time for the change in UISearchBar? I hope, reloading the tableview will call the tableview delegate methods each time. Is there any other smart way to do it?

Thanks


Solution

  • The use of UISerachDisplayController is to give you a nice user interface integration for adding search to an existing table view controller. The UISearchDisplayController does the nice transition animations and adds the grey overlay. The controller also provides the second table view though you must still provide the search bar and the search results table data source and delegate.