UITableViewCell var“表视图单元格”从来没有变异

在swift 2.0中,当我试图制作UITableViewCell自定义类的var对象时,swiftbuild议我将它转换为“let”,因为对象从来没有发生过变化。

我在UITableViewCell上有一个UIButton,但它被重命名为ABC的button的touchupinside方法调用,如果我让它的对象“让”

参考下面的一段代码:

var nameCell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(nameCellIdentifier, forIndexPath: indexPath) switch indexpath.row{ case 0: nameCell.customButton.titleLabel!.text = "ABC" case 1: nameCell.customButton.titleLabel!.text = "DEF" case 2: nameCell.customButton.titleLabel!.text = "GHI" } return nameCell 

结果:

var nameCell从来没有突变转换为让

使用

 nameCell.customButton.setTitle("ABC", forState: .Normal) 

代替

 nameCell.customButton.titleLabel!.text = "ABC" 

并更改var let

 var nameCell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(nameCellIdentifier, forIndexPath: indexPath)