Reputation: 513
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.
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"
Refer to following piece of code:
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
result:
Upvotes: 1
Views: 104
Reputation: 1956
Use
nameCell.customButton.setTitle("ABC", forState: .Normal)
instead of
nameCell.customButton.titleLabel!.text = "ABC"
and change var
to let
in
var nameCell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(nameCellIdentifier, forIndexPath: indexPath)
Upvotes: 4