ermedian
ermedian

Reputation: 145

ios search bar scope buttons doesn't update result tableview

i'm trying to implement search bar on my table view. when user enters text, filtering work well. when there is a text in search bar, scope buttons also work(it filters the results came by text filtering). my problem is when there is no text in search bar scope buttons doesn't work. filtering method filters the array successfully; but tableview doesn't update.i tried;

searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope

but it didn't work. i'm using

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
// Tells the table data source to reload when text changes
[self filterContentForSearchText:searchString
                           scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];
// Return YES to cause the search result table view to be reloaded.
return YES;

}

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption {
// Tells the table data source to reload when scope bar selection changes
[self filterContentForSearchText:self.searchDisplayController.searchBar.text
                           scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];
// Return YES to cause the search result table view to be reloaded.
return YES;

}

for text filtering. i also tried reload data, it didnt work too. i couldn't figure out why tableview updates after text change but it doesnt update after scope bar changes.

Upvotes: 4

Views: 2286

Answers (1)

ermedian
ermedian

Reputation: 145

I solved the problem. i dont use searchDisplayController anymore, instead i use textDidChange and selectedScopeButtonIndexDidChange. Also instead of using two table views(normal and self.searchDisplayController.searchResultsTableView) i'm using single table view and i change its data source, for now it seems this solved my problem. but still couldn't figure out why shouldReloadTableForSearchScope: doesn't invoke cellForRowAtIndexPath: and update my table view

Upvotes: 1

Related Questions