Scopes in UISearchController

Updated 24 March 2021


Scopes in UISearchController

Hello, in this blog we will learn how to add scopes in the search bar. By Default, UISearchController (i.e a view controller which displays search result based on the interaction with a search bar) only provide a text field for you. Adding Scopes provide you the features of filter the result based on certain conditions. Now, let’s start implementing scopes in UISearchController. We are going to create a list of Hogwarts Students and Filter them using Scopes on the basis of their Houses.

Scopes in UISearchController

Scopes Implementation

Firstly, Create an object of UISearchController in your ViewController.

Secondly, Extends the UISearchBarDelegate and UISearchResultsUpdating delegates in your View Controller.

Now, add the search bar of your UISearchController to your tableView Header.

Now, We need to provide the list for the scope and also we need to confirm the delegate of the search bar.

Finally, you need to override the selectedScopeButtonIndexDidChange methods. This method called when you select any option from the list shown in the scope. You can also get the current index of  selected item via selectedScopeButtonIndex property of UISearchBar or via selectedScope parameter.

Now, When you click on searchbar you will see the scope list as shown in the below image.

Now, let complete the application by implementing the rest of the methods.

Scope in UISearchController

Thank you for reading this article. If you want to read more articles regarding iOS Development click here or if you want to learn more about UISearchController then click here.


. . .

Leave a Comment

Your email address will not be published. Required fields are marked*

Be the first to comment.

Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home