I am using a custom cell in my TableView with a few UILabels. I need to change their colour when they are selected/highlighted.
1) Should I use tableviewWillDisplayCell: ?
2) How to differentiate the selected/highlighted cell in it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You don’t need to do anything about discovering the highlighting/selection. A UITableViewCell automatically highlights all of its subviews (the ones that can be highlighted) when it is selected. A UILabel is a view that can be highlighted; that is, it has a
highlightedproperty and it responds automatically to being highlighted.So there is no work for you to do; you’re over-thinking the problem. Just set each label’s
highlightedTextColorproperty and everything will happen automatically. As another answer points out, you can do this right in the nib, or you can do it in code.If you do need to do something special when a cell is selected, the simplest way is to use a UITableViewCell subclass and override
setSelected:animated:. But there doesn’t seem to be any need for this in your case.