0
votes

I'm having a UISearchbar in my navigationbar. When I search something the delegate:

-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
    NSLog(@"Should reload");
    [self filterContentForSearchText:searchString
                               scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                      objectAtIndex:[self.searchDisplayController.searchBar
                                                     selectedScopeButtonIndex]]];

    return YES;
}

is called so It should reload my tableview. But it doesn't. I've got two results in my search array so that's not the problem.

My init in my UITableviewController is like this:

_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
_searchBar.delegate = self;

_searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_searchBar contentsController:self];
_searchDisplayController.delegate = self;
_searchDisplayController.searchResultsDataSource = self;
_searchDisplayController.searchResultsTableView.delegate = self;

After I alloc init my UITableviewController I do this:

_poiTableView = [[POITableViewController alloc] init];
self.navigationItem.titleView = _poiTableView.searchBar;

so the searchbar is in my navigationbar and it calls searchdislaycontroller the only thing is that it doesn't reload my tableview. Before I moved the searchbar to the navigationbar, it was in the headercell of the tableview. Then it reloaded my tableview. I only moved the searchbar tot the navigationbar.

1
Could you please show the second and third blocks of code within their methods to provide context (and if too long remove unrelated code)? Could you also please confirm whether you are preparing your custom TVC POITableViewController entirely in code?andrewbuilder

1 Answers

2
votes

Implement the method searchBarShouldEndEditing: and there reload the tableview with [tableView reloadData];

Also, return YES at the end of the method since the return type is BOOL. Otherwise, it won't receive the end editing delegate calls.