Ios 在两个部分中搜索时崩溃

Ios 在两个部分中搜索时崩溃,ios,uitableview,cocoa-touch,nsfetchedresultscontroller,uisearchdisplaycontroller,Ios,Uitableview,Cocoa Touch,Nsfetchedresultscontroller,Uisearchdisplaycontroller,我有一个带有不同部分的NSFetchedResultController。 当我尝试使用UISearchDisplayController进行搜索时发生崩溃: *** Assertion failure in -[UITableViewRowData rectForRow:inSection:], /SourceCache/UIKit/UIKit-2372/UITableViewRowData.m:1630 *** Terminating app due to uncaught excepti

我有一个带有不同部分的
NSFetchedResultController
。 当我尝试使用
UISearchDisplayController
进行搜索时发生崩溃:

*** Assertion failure in -[UITableViewRowData rectForRow:inSection:], /SourceCache/UIKit/UIKit-2372/UITableViewRowData.m:1630

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'request for rect at invalid index path (<NSIndexPath 0x1d2c4120> 2 indexes [0, 1])'
返回1

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
返回2

有趣的是,如果我只有一个部分,它工作得很好


请帮忙!:)

我不确定你是否找到了答案,我想你找到了,但假设你正在使用

[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
在你的牢房里


还要确保您使用的是self.tableView

您能解释一下原因吗?我只是想知道它可能会帮助我在未来解决另一个问题。这是因为你要求self.tableView提供一个单元格。但是在搜索时,indexPath是搜索表的索引路径。索引路径不一定对self.table有效,因此无法将此索引路径传递给它。需要为单元格请求self.table,因为CellIdentifier尚未在搜索表中注册。tableView和self.tableView确实有区别。
[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
 if (tableView == self.searchDisplayController.searchResultsTableView) {
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 } else {
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
 }