gpt4 book ai didi

ios - 自定义单元格在搜索结果的 UITableView 中不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:16:03 24 4
gpt4 key购买 nike

一开始我想告诉大家,我已经研究并尝试遵循 stackoverflow 链接,例如 UISearchDisplayController and custom cell但问题依然存在

我将搜索栏和搜索显示 Controller 集成到我的 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 block 中,我将 tableview 更改为 self.tableview,它获得了正确的自定义单元格。但它采用了不正确的高度,该高度较小,因此与搜索结果的行重叠

最佳答案

在搜索结果的 if block 中,我将 tableview 更改为 self.tableview,它获得了正确的自定义单元格。但它采用了不正确的高度,该高度较小,因此与搜索结果的行重叠

为了纠正高度问题,我在 viewdidload 中添加了以下行

self.searchDisplayController.searchResultsTableView.rowHeight = self.tableView.rowHeight ;

关于ios - 自定义单元格在搜索结果的 UITableView 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23858965/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com