System behavior of the search controller:
In my application, after tapped any text tableView is still gray. I can't tap in any of searched cells.
The difference is also that when I searching I update old tableView (I don't have different tableView after searching) by using updateSearchResultsForSearchController
and reloadData after that.
The question is how to hide this gray view and give chance to tap on cells after enter any text in searchcontroller?
The way I create search controller:
UISearchController * search = [[UISearchController alloc] initWithSearchResultsController:nil];
search.searchResultsUpdater = self;
self.navigationItem.searchController = search;
self.navigationItem.hidesSearchBarWhenScrolling = YES;
self.navigationItem.searchController.searchBar.barTintColor = [UIColor blueColor];
self.navigationItem.searchController.searchBar.delegate = self;
and how I update tableView cells:
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
self.actualSearchController = searchController;
self.filteredData = [self filterContentForSearchText:searchController.searchBar.text];
[self.tableView reloadData];
}
- (NSMutableArray<MySectionContainter *> *)filterContentForSearchText:(NSString *)text {
NSMutableArray<MySectionContainter *> *sections = [NSMutableArray array];
for (MySectionContainter *section in self.tableData) {
NSArray *objects = [sectionInfo.rowObjects filteredArrayUsingPredicate:[self.filterSource predicateForSearching:text]];
if ([objects count] > 0) {
[sections addObject:[[MySectionContainter alloc] initWithTitle:section.title andObjects:objects]];
}
}
return sections;
}
- (NSPredicate *)predicateForSearching:(NSString *)text {
return [NSPredicate predicateWithBlock:^BOOL(id _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
if ([evaluatedObject isKindOfClass:[MyClass class]]) {
return [((MyClass *)evaluatedObject).title containsString:text];
}
return NO;
}];
}
Example project code: https://pastebin.com/m9V2dunB
Screenshot:
System behavior:
Test project: https://www.sendspace.com/file/2lhedj
I solve problem in your demo project by adding this line to viewDidLoad
search.dimsBackgroundDuringPresentation = NO;
Just remove dim background of UISearchController
, everything will work fine.