---
title: "Roles of Main View Controller when using Search Display Controller"  
description: "Search Display Controller is responsible for displaying searched records that are searched by Search Bar on main view controller."  
author: "Tarun Kumar"  
published: 2015-11-06  
updated: 2019-11-24  
canonical: https://www.mindstick.com/articles/11904/roles-of-main-view-controller-when-using-search-display-controller  
category: "iphone"  
tags: ["iphone", "ios", "objective c"]  
reading_time: 2 minutes  

---

# Roles of Main View Controller when using Search Display Controller

Search Display Controller is [responsible](https://answers.mindstick.com/qa/94149/who-is-one-of-the-responsible-person-for-the-department-of-space-dos) for displaying searched records that are searched by [Search Bar](https://www.mindstick.com/forum/315/how-to-achieve-similar-google-search-bar-functionality-in-c) on main view controller. Exp: when we starts a search then Search Display Controller superimposes the search [interface](https://www.mindstick.com/articles/12036/interface-in-c-sharp) over the view's of main [view controller](https://www.mindstick.com/forum/33709/how-to-use-table-view-controller-with-small-sized-in-ios), and after displayed searched results in its [table view](https://www.mindstick.com/forum/34084/how-to-change-the-height-of-table-view-in-ios).

\

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](https://answers.mindstick.com/qa/94679/how-can-we-prevent-did-you-mean-to-appear-on-google-search-results-for-our-website) 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.

Here is an example that shows how to configure a search display controller in the

\

Interface Builder:

\

```
searchController = [[UISearchDisplayController alloc] initWithSearchBar:searchBarcontentsController:self];searchController.delegate = self;searchController.searchResultsDataSource = self;searchController.searchResultsDelegate = self;
```

With the help of the table view [data source](https://www.mindstick.com/forum/160659/how-do-you-create-a-custom-filter-to-filter-any-text-in-the-data-source-in-angularjs) and [delegate methods](https://www.mindstick.com/forum/33819/getting-cell-index-number-of-collection-view-from-out-side-the-delegate-methods-in-ios) 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.       return ...;}
```

---

Original Source: https://www.mindstick.com/articles/11904/roles-of-main-view-controller-when-using-search-display-controller

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
