我有一个iPad应用程序使用分割视图控制器。在主视图中,我有一个使用故事板中定义的自定义表格单元显示的项目列表。为什么我的UISearchDisplayController不使用我自定义的tableViewCell?
单元格显示如预期的完整,在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?
修订31Jul12:
双重和三重检查所有的故事板的连接(这似乎是正确的)之后,我发现了一些...
我可以看到,实际上,我抵达一定制单元格 - 它只是看起来像标准单元格的。
当我修好了tableView:heightForRowAtIndexPath:
我注意到了一些东西。当我选择一个单元格时,我可以看到自定义单元格在那里,但由于它似乎忽略了自定义单元格的背景颜色,因此我在标准白色背景上获得了自定义白色文本,使其看起来像是空单元格。
自定义单元类中的initWithStyle:reuseIdentifier:
中的断点永远不会被击中,所以有些东西不对。
上任何指针:
- 我缺少什么,以获得在SearchResultsController细胞我的自定义背景色?
- 为什么我的自定义单元格的initWithStyle未被击中?它被设置为故事板中单元格的类。
哇。在10天后回答我自己的问题的一个投票 - 我仍然认为这是一个正确的答案。有人需要回到他们的药物。 – Thompsonian 2014-04-14 12:09:02