【问题标题】:Customized UITableView gives NSInternalInconsistencyException自定义 UITableView 给出 NSInternalInconsistencyException
【发布时间】:2019-06-26 11:40:05
【问题描述】:

我正在填充 UITableView,但出现了一个我无法理解的奇怪错误。我知道如果不进一步了解该项目,您将无法解决此问题,但有谁知道此错误消息的含义以及可能导致它的原因。

2019-06-26 13:35:22.383456+0200 TapetDemo[97178:2284706] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Attempted to access the table view's visibleCells while they were in the process of being updated, which is not allowed. Table view: <UITableView: 0x7fb4f981f000; frame = (0 85; 375 812); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600003b30570>; layer = <CALayer: 0x6000035e5640>; contentOffset: {0, 0}; contentSize: {375, 44}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <_UIFilteredDataSource: 0x600003b30660>>'
´´´

【问题讨论】:

    标签: swift uitableview tableview


    【解决方案1】:

    这就是你的错误所说的 'Attempted to access the table view's visibleCells while they were in the process of being updated, which is not allowed.

    如果没有实际代码,几乎不可能知道问题所在,但请确保您没有按照错误所说的进行操作。

    【讨论】:

    • 嗨亚瑟!感谢您的快速反馈。您是否有任何可能导致此类错误消息的示例?此外,错误消息显示:-[UITableView _visibleCellsUsingPresentationValues:] 中的断言失败
    • 可能是您尝试以错误的顺序更新值,例如您同时更新它们?或者您传递给单元格本身的数据有问题我不确定可能是什么原因。你可能想确保你使用的是tableView.reloadData(),但也要确保你没有使用太多,因为它可能是导致问题的原因。
    【解决方案2】:

    当我在 Firebase UI 中使用 Collection View 时,我也遇到过这样的异常。其中有多个代表,例如array(_ array: FUIIndexArray, didChange ref: DatabaseReference, at index: UInt)和didAdd,didRemove。在这样的自定义集合视图中,上述代表会自动执行集合视图重新加载的任务,如果我当时手动尝试在这些函数中执行reloadData(),我将面临这种不一致。

    查看您提供的代码信息后,很难找到问题所在,但我的上述方案可能会对您有所帮助。

    【讨论】:

      【解决方案3】:

      这样做的原因是您将在某个特定单元格准备好供您使用之前使用它,如错误消息所述。作为解决方案,您可以将该特定单元格/表格视图与另一个委托方法一起使用。此外,在使用带有隐藏内容的表格视图并在滚动时显示这些内容时,您将面临此类问题。作为此问题的解决方案,您可以使用 func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { }委托方法或其他委托方法根据需要。

      【讨论】:

        【解决方案4】:

        我曾经收到相同的消息,试图更新单元格中的图像。 不小心用了:

        let cell = tableView.cellForRow(at: <IndexPath>) as? <YOUR_TABLE_VIEW_CELL>
        cell?.imageView.image = image
        

        而不是出队:

         let cell = tableView.dequeueReusableCell(for: <IndexPath>) as? <YOUR_TABLE_VIEW_CELL>
         cell?.imageView.image = image
        

        希望这对以后遇到此问题的其他人有所帮助。

        【讨论】:

          猜你喜欢
          • 2013-01-09
          • 1970-01-01
          • 1970-01-01
          • 2012-12-01
          • 2012-09-01
          • 2019-09-12
          • 1970-01-01
          相关资源
          最近更新 更多