Search Display Controller is responsible for displaying searched records that are searched by Search Bar on main view controller. Exp: when we starts a search then Search Display Controller superimposes the search interface over the view's of main view controller, and after displayed searched results in its table view.
To manage searched data when using search display controller, as a helper the Main View Controller plays 4 roles, roles are as follows:
1. It has 'searchResultsDataSource' to provide data for the results table for the search results table view.
2. It has 'searchResultsDelegate' that responds on the user's selected item in the results table for the search results table view.
3. It has 'delegate' for the search display controller, that responds on events, like starting/ending of search and Showing/Hiding of the search interface.
The 'delegate' has information about the changes to the search string or search scope, this information helps to the results table view to be reloaded as needed.
4. Delegate responds on changes in the search criteria of the search bar.
searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBar
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;
the help of the table view data source and delegate methods we can check the
method's argument of table view, to find which table view is sending the
message, use following code :
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
if(tableView == self.tableView)
return ... ;
// if necessary (if self is the data source for other table view),
// check whether tableView is searchController.searchResultsTableView.