Ipad 为什么';我的UISearchDisplayController是否使用我的自定义tableViewCell?

Ipad 为什么';我的UISearchDisplayController是否使用我的自定义tableViewCell?,ipad,uitableview,uisearchbar,custom-cell,uisearchbardisplaycontrol,Ipad,Uitableview,Uisearchbar,Custom Cell,Uisearchbardisplaycontrol,我有一个使用分割视图控制器的iPad应用程序。在主视图中,我有一个使用脚本中定义的自定义表格单元显示的项目列表 单元格按预期显示,带有我在Xcode中选择的黑色背景 我正在使用UISearchBar和UISearchDisplayController 开始搜索时,列表将更改为标准的白色表格单元格 如何让SearchDisplayController使用自定义单元格 当我在搜索字段中键入时,回调将更新筛选结果的列表: - (BOOL)searchDisplayController:(UISearc

我有一个使用分割视图控制器的iPad应用程序。在主视图中,我有一个使用脚本中定义的自定义表格单元显示的项目列表

单元格按预期显示,带有我在Xcode中选择的黑色背景

我正在使用
UISearchBar
UISearchDisplayController

开始搜索时,列表将更改为标准的白色表格单元格

如何让SearchDisplayController使用自定义单元格

当我在搜索字段中键入时,回调将更新筛选结果的列表:

- (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;
}
我的表视图处理使用它来显示完整列表或筛选列表。CellIdentifier与单元情节提要中的标识符匹配:

- (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;
}
为什么我的searchDisplayController没有使用我的自定义单元格

于2012年7月31日更新

在双重和三重检查所有故事板连接(似乎是正确的)之后,我注意到一些东西

我可以看到,我实际上得到了一个自定义单元格,它看起来就像一个标准单元格

在我修复了
tableView:heightForRowAtIndexPath:
之后,我注意到了一些事情。当我选择一个单元格时,我可以看到自定义单元格在那里,但由于它似乎忽略了自定义单元格的背景色,我将自定义白色文本置于标准白色背景之上,使其看起来像一个空单元格

自定义单元格类中的
initWithStyle:reuseIdentifier:
中的断点从未被命中,因此某些地方不正确。

任何关于:

  • 在SearchResultsController中获取单元格的自定义背景色缺少什么
  • 为什么我的自定义单元格的initWithStyle没有被命中?它被设置为故事板中单元格的类

  • 苹果开发者论坛上的反馈以及以下帖子都很有帮助:


    简而言之,覆盖
    tableView:willDisplayCell:
    ,您可以适当地设置背景色。

    Wow。10天后,投票否决了回答我自己的问题——我仍然认为这是一个正确的答案。有人需要重新吃药。