搜索栏和搜索栏控制器只需点击它即可崩溃



好的,这是我第一次实现搜索栏。我已经遵循了几个教程,并开始在我的包含表视图控制器的项目中实现它。在我的情节提要中,我在自定义表视图单元格上方拖动并添加了"搜索栏和搜索栏控件"。

默认情况下,如果您只是将其拖到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的tableView:cellForRowAtIndexPath:,并确保返回的是UITableViewCell。很可能是因为您的表视图在运行时返回一个dequeueReusableCellWithIdentifier:但您的 UISearchDisplayController 的表视图没有。

我最终运行了这样的东西:

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

最新更新