adi*_*ikh 2 uitableview uisearchbar uisearchdisplaycontroller ios
首先,我想告诉我,我已经研究并尝试遵循诸如UISearchDisplayController和自定义单元格之类的stackoverflow链接,但问题仍然存在
我将搜索栏和搜索显示控制器集成到我的UITableView中.搜索功能正常但搜索结果单元格具有默认的白色单元格设计,而不是用于UITableView的自定义单元格设计.下面是我的代码,使搜索结果的Cell设计适应我的自定义设计.
- (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;
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么?
编辑:
在搜索结果的if块中,我将tableview更改为self.tableview,并获取正确的自定义单元格.但它需要较小的不正确的高度,因此搜索结果的行重叠
在搜索结果的if块中,我将tableview更改为self.tableview,并获得正确的自定义单元格.但它需要较小的不正确的高度,因此搜索结果的行重叠
为了纠正高度问题,我在viewdidload中添加了以下行
self.searchDisplayController.searchResultsTableView.rowHeight = self.tableView.rowHeight;
| 归档时间: |
|
| 查看次数: |
2491 次 |
| 最近记录: |