Reputation: 384
I'm using UISearchController and a subclassed UITableViewController as my results controller to perform search queries to a REST API on the Internet.
Instead of filtering results using the updateSearchResultsForSearchController delegate method, I wanted the user to be able to enter a query, press 'go' on the keyboard, and then present the returned results in the results controller.
After the query is performed, I'm able to get the results controller to load my results, however the table view isn't reloading data when I ask it to. Instead, I have to drag down on the tableview for it to properly reload.
My question is - is there a way to force the results controller to manually refresh after my query is performed? I tried calling [self.searchcontroller.searchresultscontroller.tableVIew reloadData] but am unable to get the results array to load properly.
Search Controller setup code
//Setup search controller
_resultsController = [[RxLookupResultsViewController alloc] init];
_searchController = [[UISearchController alloc] initWithSearchResultsController:_resultsController];
[self.searchController.searchBar sizeToFit];
self.searchController.searchResultsUpdater = self;
self.tableView.tableHeaderView = self.searchController.searchBar;
[self.searchController.searchBar setReturnKeyType:UIReturnKeyGo];
self.resultsController.tableView.delegate = self;
self.searchController.delegate = self;
self.searchController.dimsBackgroundDuringPresentation = YES;
self.searchController.searchBar.delegate = self;
self.searchController.searchBar.tintColor = [UIColor darkTextColor];
//NSArray *scope = @[@"Scope 1", @"Scope 2"];
//self.searchController.searchBar.scopeButtonTitles = scope;
self.searchController.searchBar.showsScopeBar = NO;
self.definesPresentationContext = YES;
After the query is performed based on the search bar text, I run the following:
_resultsController.filteredCodes = searchResultsDrugNames;
[_resultsController.tableView reloadData];
Any pointers? I'm sure its something simple that I'm overlooking, could use a fresh set of eyes on this.
Thanks!
Upvotes: 0
Views: 673
Reputation: 384
Daniel Z's comment about the reload being called on the main thread was the solution. Forgot the query was being called on a background thread.
Upvotes: 1