gpt4 book ai didi

ios - 在 UISearchResultsTableView 中获取 "Assertion failure"

转载 作者:行者123 更新时间:2023-11-28 18:32:07 24 4
gpt4 key购买 nike

当我开始在 SearchBar 中输入搜索文本时出现以下错误

Assertion failure in -[UISearchResultsTableView _configureCellForDisplay:forIndexPath:]

cellForRowAtIndexPath Search Display Controller 代码如下:

if(tableView == self.searchDisplayController.searchResultsTableView)
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if(cell == nil)
{
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}

cell.textLabel.text = [search objectAtIndex:indexPath.row];

return cell;
}

最佳答案

用这个代码替换你的代码可能会起作用。

if(tableView == self.searchDisplayController.searchResultsTableView)
{
static NSString *CellIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if(cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [search objectAtIndex:indexPath.row];

return cell;
}

因为一旦您发现单元格对象再次为 nil,您将使用 [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 分配带有 nil 对象的单元格;这就是它不起作用的原因。

关于ios - 在 UISearchResultsTableView 中获取 "Assertion failure",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26686684/

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