相关疑难解决方法(0)

滚动表格视图后点击以选择行时,如何解决崩溃问题?

我有一个这样的表视图:

在此处输入图片说明

当用户点击一行时,我要取消选中最后一行并选中选定的行。所以我写了这样的代码:(例如,我的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”

该行显示错误:

在此处输入图片说明

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

xcode uitableview tableviewcell ios swift

2
推荐指数
1
解决办法
1122
查看次数

标签 统计

ios ×1

swift ×1

tableviewcell ×1

uitableview ×1

xcode ×1