Swift. Change Color of Custom Tableview Cell Label when selected

user3110353 picture user3110353 · Jun 24, 2015 · Viewed 17.9k times · Source

I have a Custom Tableview cell in swift and in that cell a label.

I want to be able to change the label when you select a cell.

How can I reference my custom UITableviewCell label in didSelectRowAtIndexPath

In Objective C to reference my custom cell in didSelectRowAtIndexPath I would use the following:

MPSurveyTableViewCell *cell = (MPSurveyTableViewCell *)[tableViewcellForRowAtIndexPath:indexPath];
cell.customLabel.TextColor = [UIColor redColor]; 

What must I do in swift to achieve the same result?

Answer

Shamas S picture Shamas S · Jun 24, 2015

You just need to translate the same code to Swift.

var myCell = tableView.cellForRowAtIndexPath(indexPath) as! MPSurveyTableViewCell
myCell.customLabel.textColor = UIColor.redColor()