gpt4 book ai didi

ios - 在两个部分中搜索时崩溃

转载 作者:技术小花猫 更新时间:2023-10-29 10:30:17 25 4
gpt4 key购买 nike

我有一个包含不同部分的 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

有趣的是,如果我只有一个部分,它就完美无缺。

请帮忙! :)

最佳答案

不确定你是否弄明白了,我想你已经弄明白了,但假设你正在使用

[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

关于ios - 在两个部分中搜索时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14336199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com