Ios 搜索栏和搜索栏控制器只需点击它就会崩溃

Ios 搜索栏和搜索栏控制器只需点击它就会崩溃,ios,objective-c,uitableview,uisearchbar,uisearchdisplaycontroller,Ios,Objective C,Uitableview,Uisearchbar,Uisearchdisplaycontroller,这是我第一次实现搜索栏。我已经学习了一些教程,并开始在包含tableviewcontroller的项目中实现它。在我的故事板中,我在自定义tableview单元格上方拖动并添加了一个“搜索栏和搜索栏控制器” 默认情况下,如果您只是将其拖动到tableview控制器中,什么也不做,只运行程序并点击搜索栏,它将不会做任何事情,因为还没有完成任何实现 但在我的例子中,只要点击它,程序就会崩溃,并显示以下内容: 2013-09-24 05:29:32.468 TechY[4189:a0b] *** As

这是我第一次实现搜索栏。我已经学习了一些教程,并开始在包含tableviewcontroller的项目中实现它。在我的故事板中,我在自定义tableview单元格上方拖动并添加了一个“搜索栏和搜索栏控制器”

默认情况下,如果您只是将其拖动到tableview控制器中,什么也不做,只运行程序并点击搜索栏,它将不会做任何事情,因为还没有完成任何实现

但在我的例子中,只要点击它,程序就会崩溃,并显示以下内容:

2013-09-24 05:29:32.468 TechY[4189:a0b] *** Assertion failure in -[UISearchResultsTableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2903.2/UITableView.m:6235
2013-09-24 05:29:32.533 TechY[4189:a0b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

所以我就停在这里,无法完成其余的实现。有人能指出问题出在哪里吗?谢谢

您需要查看UITableViewDataSource的
表视图:cellforrowatinexpath:
并确保返回的是
UITableViewCell
。很可能是因为在运行
dequeueReusableCellWithIdentifier:
时,表视图返回一个,但UISearchDisplayController的表视图不返回

我最后做了这样的事情:

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil && tableView != self.tableView) {
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
}