Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't my UISearchDisplayController use my custom tableViewCell?
    text
    copied!<p>I have an iPad app using a split-view controller. Within the master view, I have a list of items displayed using a custom table cell defined in the storyboard.</p> <p>The cells display as expected complete with the dark background I selected in Xcode.</p> <p>I am using a <code>UISearchBar</code> and <code>UISearchDisplayController</code>.</p> <p>When I begin a search, the list changes to standard, white table cells.</p> <p>How can I get the SearchDisplayController to use my custom cells?</p> <p>As I type in the search field, the callback updates a list of filtered results:</p> <pre><code>- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { [self filterAvailableChannelsForSearchText:searchString scope:[[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]]; [self.searchDisplayController.searchBar selectedScopeButtonIndex]]]; return YES; } </code></pre> <p>This is used by my table view handling to present either the full list or the filtered list. The CellIdentifier matches the identifier in the storyboard for the cell:</p> <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if (tableView == self.searchDisplayController.searchResultsTableView) return [self.filteredAvailableChannel count]; else return [[self availableChannelList] count]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"AvailableChannelCell"; FVAvailableChannelCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Configure the cell... FVChannel *channel = nil; int row = [indexPath row]; if (tableView == self.searchDisplayController.searchResultsTableView) channel = [self.filteredAvailableChannel objectAtIndex:row]; else channel = [[self availableChannelList] objectAtIndex:row]; cell.idLabel.text = channel.channelID; cell.nameLabel.text = channel.channelName; cell.unitLabel.text = channel.unitName; return cell; } </code></pre> <p>Why isn't my searchDisplayController using my custom cells?</p> <p><strong>UPDATED 31Jul12</strong>:</p> <p>After double and triple checking all the storyboard connections (which seem to be correct), I noticed something…</p> <p>I can see that I'm actually <strong>GETTING</strong> a custom cell - it just <strong>LOOKS</strong> like a standard cell. </p> <p>After I fixed <code>tableView:heightForRowAtIndexPath:</code> I noticed something.  When I select a cell, I can see that the custom cell is there, but since it seems to ignore the background color of my custom cell, I'm getting my custom white text on top of the standard white background making it appear like an empty cell.</p> <p>Breakpoints in <code>initWithStyle:reuseIdentifier:</code> in the custom cell class never get hit so something is not right there.  </p> <p>Any pointers on:</p> <ol> <li>What am I missing to get my custom background color on the cells in a SearchResultsController?</li> <li>Why does the initWithStyle for my custom cell not get hit?  It's set as the class for the cell in the storyboard.</li> </ol>
 

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