UITableViewCell var "table view cell"从未变异 [英] UITableViewCell var "table view cell" was never mutated

查看:41
本文介绍了UITableViewCell var "table view cell"从未变异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 swift 2.0 中,当我尝试创建 UITableViewCell 自定义类的 var 对象时,swift 建议我将其转换为let",因为对象从未发生过变异.

In swift 2.0 when I tried to make var object of UITableViewCell custom class, swift is suggesting me to convert it to "let" because object was never mutated.

我在 UITableViewCell 上有一个 UIButton,但如果我将它的对象设置为让",它会在按钮的 touchupinside 方法调用中重命名为 ABC

I have a UIButton on UITableViewCell but it is renamed to ABC on touchupinside method call of the button if i make its object to "let"

参考以下代码:

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

结果:

推荐答案

使用

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

代替

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

并将

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

这篇关于UITableViewCell var "table view cell"从未变异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆