I have found a tutorial on this website:
http://jduff.github.com/2010/03/01/building-a-searchview-with-uisearchbar-and-uitableview/
…but I am stuck here:
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
// You'll probably want to do this on another thread
// SomeService is just a dummy class representing some
// api that you are using to do the search
NSArray *results = [SomeSerivece doSearch:searchBar.text];
[searchBar setShowsCancelButton:NO animated:YES];
[searchBar resignFirstResponder];
self.tableView.allowsSelection = YES;
self.tableView.scrollEnabled = YES;
[tableData removeAllObjects];
[tableData addObjectsFromArray:results];
[self.tableView reloadData];
}
I can’t understand what I have to write instead of SomeService. It is under comment, but I can’t understand. I already have an array with all the content of the table view…so?? What do I have to do??
It looks like some service is the class that actually searches the array based on xyz criteria and returns the results. If I remember correctly UISearchBar automatically does this for you now – it is possible that the tutorial you are using is outdated.
I haven’t used it personally, but the following may be more helpful; it uses a UISearchDisplayController, which handles the search results for you instead of forcing you to do it manually.
http://ygamretuta.me/2011/08/10/ios-implementing-a-basic-search-uisearchdisplaycontroller-and-interface-builder/
If you’d rather use the first tutorial, you’ll have to create/find a search class to use on the array.