I have an app which displays quite a lot of data in a UITableView
. I already added the UISearchBar
and UISearchDisplayController
in Interface Builder to the UITableView
. But I do not know how to use it. If someone could provide a quick solution to this, I would be grateful. I just require it to work as you type to find matches of the search query in the UITableView
cells (or from an array).
UPDATE 1: Here's the code from thenumberOfRowsInSection
method:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (isSearching) {
return [searchResults count];
}
else {
if (section == 0) {
return 1;
}
else if (section == 1) {
return [basicQuantities count];
}
else if (section == 2) {
return [physicalQuantities count];
}
}
return nil;
}
Demo Project
In your .h File
In your .m File
Filling the sample data (Optional Only For Demo Purpose)
Now implement the Table View Delegate and Datasource
Search Function Responsible For Searching
Search Bar Implementation
Here is a good tutorial how to do that. It's too much to just write about it :)
http://www.appcoda.com/how-to-add-search-bar-uitableview/