0

我已经声明了一个 String 类型的可选属性。在 viewDidload 中,我调用了一个对该属性执行可选绑定的函数:

public var localMsgIdToBeHighlighted: String? = nil

以下是我的方法:

 private func performInitialBottomScrolling() {
    if let safeLocalMsgId = self.localMsgIdToBeHighlighted, let safeMsgList = self.messageList {
        var index = 0
        var indexPath: IndexPath? = nil
        for msgModel in safeMsgList {
            if msgModel.localMsgId == safeLocalMsgId {
                indexPath = IndexPath(row: index, section: 0)
                break
            }
            index = index + 1
        }
        if let safeIndexPath = indexPath {
            self.tblViewChatLog.scrollToRow(at: safeIndexPath, at: .bottom, animated: false)
            if let cell = self.tblViewChatLog.cellForRow(at: safeIndexPath) {
                cell.setHighlighted(true, animated: true)
            }
        } else {
            self.scrollToBottom(animation: false)
        }
    } else {
        self.scrollToBottom(animation: false)
    }
}

它工作正常,但突然在这种方法中开始发生崩溃: 参考这个截图

这次崩溃的原因可能是什么?

4

0 回答 0