我有一个这样的表视图:

当用户点击一行时,我要取消选中最后一行并选中选定的行。所以我写了这样的代码:(例如,我的lastselected = 0)
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var lastIndexPath:NSIndexPath = NSIndexPath(forRow: lastSelected, inSection: 0)
var lastCell = self.diceFaceTable.cellForRowAtIndexPath(lastIndexPath) as! TableViewCell
var cell = self.diceFaceTable.cellForRowAtIndexPath(indexPath) as! TableViewCell
lastCell.checkImg.image = UIImage(named: "uncheck")
cell.checkImg.image = UIImage(named: "check")
lastSelected = indexPath.row
}
Run Code Online (Sandbox Code Playgroud)
当我连续滚动而不滚动时,一切正常。我意识到,当我运行代码并立即滚动表并选择一行时。我的程序将崩溃并显示错误:“致命错误:在展开可选值时意外发现nil”
该行显示错误:

我不知道这里有什么问题吗?