12

我有一个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])'

我检查了一下,我的搜索数组确实有两个条目(预期结果):

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

返回 1

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

返回 2

有趣的是,如果我只有一个部分,它就可以完美运行。

请帮忙!:)

4

1 回答 1

38

不知道你是否明白了,我想你做到了,但假设你正在使用

[self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

在你的 cellForRowAtIndexPath

 if (tableView == self.searchDisplayController.searchResultsTableView) {
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier];
 } else {
    cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
 }

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

于 2013-02-24T23:44:39.820 回答