ios - 试图为同一索引路径使多个单元格出队,这是不允许的

标签 ios objective-c uitableview

我有一个非常简单的 UITableView,自 iOS6 以来一直运行良好....我最近尝试从 iOS10 到 iOS11 进行新构建,现在我得到了这个我以前从未见过的新 NSInternalConsistency 异常,它实际上是从新的 iOS 版本中脱颖而出的....

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to dequeue multiple cells for the same index path, which is not allowed. If you really need to dequeue more cells than the table view is requesting, use the -dequeueReusableCellWithIdentifier: method (without an index path). Cell identifier: WorkOrderCell, index path: {length = 2, path = 0 - 0}'

我已经回顾了很多教程,我觉得这段代码没有什么特别的错误..事实上正常的网格加载工作正常,这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"WorkOrderCell" forIndexPath:indexPath];



    // Configure the cell...  do some work, return it



    return cell;
}

有没有其他人遇到过这个问题,你做了什么来解决它?

我应该说得更具体一些,正常的 UITableView 确实加载得很好,这个具体问题是我有一个 SearchBar,当用户输入搜索时,我过滤结果并显示结果网格:

//Start Search/Filter Code
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"Job contains[cd] %@ or Address contains[cd] %@ or WorkOrderId contains[cd] %@ or Supervisor contains[cd] %@", searchText, searchText, searchText, searchText];
    self.filteredWorkOrders = [self.workOrders filteredArrayUsingPredicate:resultPredicate];
}


-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString
                               scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                      objectAtIndex:[self.searchDisplayController.searchBar
                                                     selectedScopeButtonIndex]]];

    return YES;
}

过滤器代码本身工作正常,只是它触发了 UITableView 委托(delegate)触发,它开始使单元格出队(在搜索结果网格中应该是空的??)

无论如何,我需要一些帮助......

最佳答案

不要在您的cellForRowAtIndexPath 方法(或任何其他数据源和委托(delegate)方法)中使用self.tableView。使用 tableView 参数。

当您的数据源和委托(delegate)方法用于多个表格 View 时,这一点非常重要。

关于ios - 试图为同一索引路径使多个单元格出队,这是不允许的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47724733/

相关文章:

ios - 在 iOS 9 中设置 UIView 的碰撞边界路径

ios - 发布后更新 TableView

ios - PubNub 本地消息重复?

iphone - 如何开始使用 airplay?

ios - BluetoothManager 不适用于 iOS 7

ios - UIView 页面 curl 动画不适用于 block

ios - AppDelegate 类不适用于 iOS Swift 应用程序中的 Obj-C 嵌入式库

iphone - NSCoding 和 ARC

ios - tablecell 背景仅显示自定义单元格,但显示自定义单元格使其无法选择

ios - 输入一个 Autocomplete TextField 会弹出另一个 Autocomplete TextField TableView