views:

103

answers:

1

Dear All,

In my app, I use a label to display a specified color by set background color in a customized UITableViewCell (because this color maybe changed according incoming data from internet), after viewDidLoad, everything is ok, but when this cell is selected (highlighted) the color is cleared.

After searching, I found out that some someone have to subclass UITableViewCell and overwrite setHighlight method to not clear label background color. I have tried but unlucky.

So Does anybody know how to do this? the right way to subclass UITableViewCell, then use it in UITableViewController to not clear label background color? Please help me.

Thanks for any advice.

A: 

From the latest UITableViewCell documentation:

Note: If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source. Changes to the background colors of cells in a group-style table view has an effect in iOS 3.0 that is different than previous versions of the operating system. It now affects the area inside the rounded rectangle instead of the area outside of it.

Also, review the Table View Programming Guide for iOS for some of the best documentation.

petert
Sorry, I mean that: how to set background color of an UILabel inside UITableViewCell so that this background color would not be cleared (transparent) when this cell is selected (highlighted)
Son Nguyen
Are you sure this doesn't work: label.backgroundColor = [UIColor redColor];I can't verify this right now, but don't remember having problems with this before.
petert