【发布时间】:2015-03-31 19:31:00
【问题描述】:
首先我想说的是,我已经研究并尝试关注 UISearchDisplayController and custom cell 等 stackoverflow 链接,但问题仍然存在
我的 UITableView 中集成了搜索栏和搜索显示控制器。搜索功能工作正常,但搜索结果单元格具有默认的白色单元格设计,而不是用于 UITableView 的自定义单元格设计。下面是使搜索结果的单元格设计适应我的自定义设计的代码。
- (void)viewDidLoad
{
[super viewDidLoad];
[self.searchDisplayController.searchResultsTableView registerClass:[ItemCellTableViewCell class] forCellReuseIdentifier:@"Cell"];
if(!self.document){
[self initDocument];
}
self.filteredItemCatalogArray = [[NSMutableArray alloc]init];
self.itemCatalogTableView.dataSource = self;
self.itemCatalogTableView.delegate = self;
[self.itemCatalogTableView reloadData];
self.itemCatalogTableView.backgroundColor = [UIColor clearColor];
self.itemCatalogTableView.opaque = NO;
self.itemCatalogTableView.bounces = YES;
self.itemCatalogTableView.backgroundView = nil;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
if(tableView == self.searchDisplayController.searchResultsTableView)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//cell fields customization
cell.backgroundColor = [UIColor clearColor];
cell.opaque = NO;
return cell;
}
else
{
ItemCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//cell fields customization
cell.backgroundColor = [UIColor clearColor];
cell.opaque = NO;
return cell;
}
}
我在这里错过了什么?
已编辑:
在搜索结果的 if 块中,我将 tableview 更改为 self.tableview 并获得正确的自定义单元格。但它采用了不正确的高度,该高度较小,因此与搜索结果的行重叠
【问题讨论】:
-
在搜索结果的 if 块中,我将 tableview 更改为 self.tableview 并获得了正确的自定义单元格。但它采用了不正确的高度,该高度较小,因此与搜索结果的行重叠
-
为了纠正高度问题,我在 viewdidload self.searchDisplayController.searchResultsTableView.rowHeight = self.tableView.rowHeight 中添加了以下行;
标签: ios uitableview uisearchbar uisearchdisplaycontroller