我在我的 iPhone 项目中使用 UIStoryboard,并且有一个 Controller 是 UITableViewController 的子类并且有 UISearchDisplayController。
在 tableView:cellForRowAtIndexPath,我正在使用以下方法获取单元格:
MyCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
CellIdentifier 是我的原型(prototype)单元格的标识符。这在显示表格行时可以正常工作,但是一旦我编辑了搜索栏,并且 View 试图显示搜索结果,我得到了 nil 单元格。
最佳答案
添加这个:
if (cell == nil) {
cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}
而且,如果像我一样,您更改了表格单元格行的 rowHeight,您也需要实现此方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return self.tableView.rowHeight;
}
关于ios - 在 UIStoryBoard 上使用 UISearchDisplayController 时无单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8392152/