gpt4 book ai didi

ios - UITableViewCell var "table view cell"从未发生过变化

转载 作者:搜寻专家 更新时间:2023-11-01 06:19:27 25 4
gpt4 key购买 nike

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

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

引用以下代码:

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 从未发生过突变将其转换为 let

最佳答案

使用

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

代替

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

并将 var 更改为 let

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

关于ios - UITableViewCell var "table view cell"从未发生过变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36887112/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com