微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – 尝试将相同索引路径的多个单元格出列,这是不允许的

我有一个非常简单的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];
    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委托来触发,它开始出列单元格(在搜索结果网格中应该是空的?)

无论如何,我可以使用这个帮助…..

解决方法

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

当您的数据源和委托方法用于多个表视图时,这非常重要.

原文地址:https://www.jb51.cc/iOS/328737.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐