Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't my search table view appear when beginning search?
    text
    copied!<p>I've wired a UISearchDisplayController into my app along with a search bar. I've initialized it as so:</p> <pre><code>self.filteredObjectArray = [NSMutableArray arrayWithCapacity:[self.objectArray count]]; UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 43)]; searchBar.delegate = self; [self.view addSubview:searchBar]; UISearchDisplayController *searchDisplay = [[UISearchDisplayController alloc] initWithSearchBar:searchBar contentsController:self]; searchDisplay.delegate = self; searchDisplay.searchResultsTableView.delegate = self; searchDisplay.searchResultsDataSource = self; searchDisplay.searchResultsDelegate = self; </code></pre> <p>Which is pretty much the way I've seen it in other examples. I've also implemented the appropriate delegate methods, with the important filterContentForSearchText and the shouldReload* methods shown below:</p> <pre><code>- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope { [self.filteredObjectArray removeAllObjects]; // First clear the filtered array. for (XRay *xray in objectArray) { NSString *combinedLabel = [self combinedLabel:xray]; if ([combinedLabel rangeOfString:searchText options:(NSCaseInsensitiveSearch)].location != NSNotFound) { [self.filteredObjectArray addObject:xray]; } } } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { [self filterContentForSearchText:searchString scope: [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]]; return YES; } - (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption { [self filterContentForSearchText:self.searchDisplayController.searchBar.text scope: [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]]; return YES; } </code></pre> <p>However my search is not working when I give the search text box focus or input any characters. You'll also notice that the greyed out view does not appear over my regular table view.</p> <p><img src="https://i.stack.imgur.com/t1Iwe.jpg" alt="Screenshot"></p> <p><strong>EDIT</strong> cellForRowAtIndexPath</p> <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"XraySearchChoice"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } XRay *xray = nil; if (tableView == self.searchDisplayController.searchResultsTableView) { xray = [self.filteredObjectArray objectAtIndex:indexPath.row]; } else { xray = [self.objectArray objectAtIndex:indexPath.row]; } cell.textLabel.text = [self combinedLabel:xray]; return cell; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload