This is interesting. Got some examples of UISearchBar and the like of capturing the text input and resignFirstResponder when finished with search.
Core Data has good examples of tableView and how to retrieve and display data.
However, not much info is available, even from books, blogs and others on how to use UISearch with an existing TableView with data from Core Data.
Seems like you are on your own when using these 3 related APIs. Together, these 3 APIs can give you the best way to view and search data fetched using Core Data.
Core Data gives you good memory management when using a large database. Data is faulted, read from the database for viewable cells. No need to create a huge array to hold the data.
One way to differentiate which table to display; i.e. normal or searched can be dependent on
// when we start/end showing the search UI
- (void) searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
useSearch = YES;
}
- (void) searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller
{
useSearch = NO;
}
You can use this flag to determine which table to view for your UITableViewDelegate methods.
// called when cancel button pressed
- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar {
searchBar.text = nil;
[searchBar resignFirstResponder];
[searchBar setShowsCancelButton:YES animated:YES];
// reset the fetch search controller
fetchedSearchResultsController = nil;
}
You also need to reset the fetchedSearchResultsController at the end of search. Have to make sure that search results are refreshed upon new search.