ios - 在 UIStoryBoard 上使用 UISearchDisplayController 时无单元格

标签 ios xcode4.2 searchbar uistoryboard

我在我的 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/

相关文章:

objective-c - 观看更改以保留计数

iphone - XCODE 4.2 中的构建文件夹位置

ios - 没有结果时隐藏海关部分?

iOS SearchBar 和 SeachDisplayController 错位

swift - 想快速创建一个像谷歌这样的搜索栏

objective-c - 这应该自动发布吗?或者有没有办法手动完成?

ios - 在所有 iOS 设备中粘贴 2 个 ImageView 尺寸

ios - 尝试加载共享 pdf 时出现错误 : Value of type 'UIView' has no member 'view' ,

iphone - WebView 无法正确显示推文

xcode - 在 Xcode 4 中清除问题导航器