值为零的属性具有“无法读取的数据”并导致崩溃。 Swift 4.2 |的iOS

时间:2019-05-07 04:50:37

标签: ios swift uitableview optional-binding

我已经声明了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)
    }
}

它工作正常,但是突然在这种方法下发生崩溃: Refer to this screenshot

此崩溃的原因可能是什么?

0 个答案:

没有答案