Skip to content

Instantly share code, notes, and snippets.

@tommypeps
Created October 2, 2015 13:37
Show Gist options
  • Save tommypeps/42732308212bfe485813 to your computer and use it in GitHub Desktop.
Save tommypeps/42732308212bfe485813 to your computer and use it in GitHub Desktop.
-(void)configSearch
{
self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0);
self.tableView.tableHeaderView = self.searchController.searchBar;
self.searchController.searchBar.delegate = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
}
-(void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
NSString *searchString = [self.searchController.searchBar text];
[self updateFilteredContentForProductName:searchString type:nil];
[self.tableView reloadData];
}
#pragma mark - UISearchBarDelegate
// Workaround for bug: -updateSearchResultsForSearchController: is not called when scope buttons change
- (void)searchBar:(UISearchBar *)searchBarselectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
[self updateSearchResultsForSearchController:self.searchController];
}
#pragma mark - Content Filtering
//TODO:HECHO
- (void)updateFilteredContentForProductName:(NSString *)productName
type:(NSString *)typeName
{
[_searchResult removeAllObjects];
for (JRCenterInfo *center in _listElement) {
NSUInteger searchOptions = NSCaseInsensitiveSearch | NSDiacriticInsensitiveSearch;
NSRange productNameRange = NSMakeRange(0, center.name.length);
NSRange foundRange = [center.name rangeOfString:productName options:searchOptions range:productNameRange];
if (foundRange.length > 0) {
[self.searchResult addObject:center];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment