【问题标题】:iOS 14 Fatal Exception: NSInternalInconsistencyException Path wasn't found in current data modeliOS 14 致命异常:在当前数据模型中找不到 NSInternalInconsistencyException 路径
【发布时间】:2020-10-23 23:48:33
【问题描述】:

升级到 iOS 14 后出现以下错误。我正在使用一个名为 MessageKit 的库,它是用它构建的。

在准备更新 {length = 2, path = 25 - 0} 的可见视图时,在当前数据模型中找不到并且不在更新动画中

有谁知道这个错误是什么意思?崩溃指向集合视图上的方法scrollToBottom。看起来无论出于何种原因,模型中的最后一个项目在运行动画或其他内容时不再存在。我想知道这是否可能是由于打字指示器,但我不确定。

func insertMessage(_ message: NewMessageModel) {
    // Reload last section to update header/footer labels and insert a new one
    DispatchQueue.main.async {
        
        self.isPerformingBatchUpdates = true
        self.messagesCollectionView.performBatchUpdates({
            self.messages.append(message)   //The messages object can only be modified on the main thread
            self.checkLastMessageSent(message: message)
            self.messagesCollectionView.insertSections([self.messages.count - 1])
            if self.messages.count >= 2 {
                self.messagesCollectionView.reloadSections([self.messages.count - 2])
            }
        }, completion: { [weak self] _ in
            self?.messagesCollectionView.scrollToBottom(animated: true)
            self?.isPerformingBatchUpdates = false
        })
    }

}

【问题讨论】:

  • 每条消息都在自己的部分中吗?

标签: ios swift uicollectionview messagekit


【解决方案1】:

使用下面的功能,它会正常工作的。

func insertMessage(_ message: MockMessage) {
    messageList.append(message)
    // Reload last section to update header/footer labels and insert a new one
    messagesCollectionView.performBatchUpdates({
        messagesCollectionView.insertSections([messageList.count - 1])
        if messageList.count >= 2 {
            messagesCollectionView.reloadSections([messageList.count - 2])
        }
    }, completion: { [weak self] _ in
        if self?.isLastSectionVisible() == true {
            self?.messagesCollectionView.scrollToBottom(animated: true)
        }
    })
}

【讨论】:

  • 所以你建议调用滚动到底部时需要进行 lastSectionVisible 检查?
【解决方案2】:

基于MessageKit 的新更改,您现在需要使用scrollToLastItem() 而不是scrollToBottom(animated:)

func insertMessage(_ message: NewMessageModel) {
    DispatchQueue.main.async {
        
        self.isPerformingBatchUpdates = true
        self.messagesCollectionView.performBatchUpdates({
            self.messages.append(message)
            self.checkLastMessageSent(message: message)
            self.messagesCollectionView.insertSections([self.messages.count - 1])
            if self.messages.count >= 2 {
                self.messagesCollectionView.reloadSections([self.messages.count - 2])
            }
        }, completion: { [weak self] _ in
            self?.messagesCollectionView.scrollToLastItem() // Use it instead of using `scrollToBottom(animated:)`
            self?.isPerformingBatchUpdates = false
        })
    }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-27
    相关资源
    最近更新 更多