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.
The cells display as expected complete with the dark background I selected in Xcode.
I am using a UISearchBar
and UISearchDisplayController
.
When I begin a search, the list changes to standard, white table cells.
How can I get the SearchDisplayController to use my custom cells?
As I type in the search field, the callback updates a list of filtered results:
- (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;
}
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:
- (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;
}
Why isn't my searchDisplayController using my custom cells?
UPDATED 31Jul12:
After double and triple checking all the storyboard connections (which seem to be correct), I noticed something…
I can see that I'm actually GETTING a custom cell - it just LOOKS like a standard cell.
After I fixed tableView:heightForRowAtIndexPath:
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.
Breakpoints in initWithStyle:reuseIdentifier:
in the custom cell class never get hit so something is not right there.
Any pointers on:
- What am I missing to get my custom background color on the cells in a SearchResultsController?
- Why does the initWithStyle for my custom cell not get hit? It's set as the class for the cell in the storyboard.