What is the best practice to filter the NSFetchedResultsController data?
do i need to re-initialize it every time the searchbar’s text changes?
I am using a UISearchDisplayControllers and i’m implementing:
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString;
Thx.
How is Guy’s answer code any different from the question? As far as I can guess, the filterContentForSearchText:scope method is called by the shouldReload methods?
Anyway, here’s some similar code that I added in the CoreDataBooks sample to include search. Add a Search Display Controller in IB for the CoreDataBooks example. Then I added code to RootViewController.m as follows:
PS. To answer Vivas, using a UISearchDisplayController it creates a new table view automatically for overlaying the filtered list. You can check which tableView is being used as shown in the docs, but in the simplest setup it just works because the fetchedResultsController is either showing a filtered version in the search’s table view or showing all data in your table view.