In this tutorial, we are going to discuss about implementation of Search Bar with Table View using Objective-C Language in iOS application in Xcode 8. Search Bar is a tool which is used for the purpose of searching any item. 

Example – In real scenario, user search any contact in search bar available in contact list.

Before proceeding, you need to download the Xcode project of Table View Controller from below link.

Following are the steps to implement Search Bar:

Step 1: Firstly you need to download the Xcode project of Table View Controller from below link.

Download Xcode Project

Now, open up the downloaded Xcode project.

Step 2: Adding UISearchBar into existing Table View Controller.

On your project, click on main.storyboard file available in the project navigator, and then select the UISearchBar from object library, drag it to the Table View Controller, just above the cell, it will look like below.

Step 3: Declaring property for SearchBar & add its protocol.

Select the Assistant Editor and create IBOutlet property for UISearchBar by holding Ctrl button. It will open up a popup view like below then enter the Name as ‘searchBar’ and click Connect.

Add delegate protocol

Step  4: Declare empty Mutable Array and helping variable.

Create MutableEmpty array named ‘filteredDevices’ using NSMutableArray which is needed to insert searched/filtered data into it. The helping variable named ‘isFiltered’ is Bool type and make it by default ‘False’.



Step 6: Set its delegate method with search coding in it.

Delegate Method:
– (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
}

Step 7: Complete code of ViewController.h

All property defined in ViewController.h file will be shown as below:



Step 8: Complete Code in ViewController.m file

In ViewController.m file, displaying value of stepper will be passed to Label in stepper action method as shown in below screenshot.

Moreover, changes to be made in tableview datasource & delegate methods to display data according to search data as mentioned in below screenshot. 

Step 9: Run Simulator

Finally, Build and Run the application & search item(s) using searchBar and you will get the output like below.

Have Fun !

You can also watch its video on below link: