PDA

View Full Version : custom UITableViewCell selectedCell color setting




arnieterm
Jan 16, 2009, 06:57 AM
I have created a custom UITableViewCell that contains three labels and one image. The table view is showing data fine. What I am stuck in is when user touches cell of tableview, then I want to show the background color of the cell other than the default color values for highlighting the selection of cell.

I have searched a lot but does not find any relevent solution for this.
Thanks
Arnie



dejo
Jan 16, 2009, 10:53 AM
I have created a custom UITableViewCell that contains three labels and one image. The table view is showing data fine. What I am stuck in is when user touches cell of tableview, then I want to show the background color of the cell other than the default color values for highlighting the selection of cell.
Are you wanting to leave the cell selected? I.e. the background color stays that way and looks highlighted?

If so, the Mobile HIG recommends not doing so:
Table views provide feedback when users select list items. Specifically, when an item can be selected, the row containing the item highlights briefly when a user selects it to show that the selection has been received. Then, an immediate action occurs: Either a new view is revealed or the row displays a checkmark to indicate that the item has been selected. The row never remains highlighted, because table views do not display a
persistent selected state.

If not, I would suggest looking at UITableViewCell's selectedBackgroundView property and adjusting the backgroundColor through it.

arnieterm
Jan 20, 2009, 08:48 AM
Where should I set the selected background's cell background color?
And should it be done this way
cell.selectedBackgroundView.backgroundColor=[UIColor blackColor];
Should it be in tableview:didSelectRowatIndexPath, if yes then how can we get the current cell?
Thanks
Arnie

arnieterm
Jan 29, 2009, 06:29 AM
Can anybody tell where and how should I set the selectedBackgroundView's color to some custom color?
I have created a custom UITableViewCell
Thanks
Arnieterm

dejo
Jan 29, 2009, 10:24 AM
How?

Rather than give you the answer outright, I'm gonna try and prod you in the right direction, okay? Along the lines of the "teach a man to fish..." mantra. So, according to the Developer Documentation, what class of object is UITableViewCell's selectedBackgroundView?

Where?

I'm afraid we need some more details on how you are using it. But let's deal with that first question first.

arnieterm
Jan 29, 2009, 11:34 AM
Answer to your first question:
UIView

dejo
Jan 29, 2009, 11:55 AM
Answer to your first question:
UIView
Correct. And is there a property of UIView that may relate to it's background color?

arnieterm
Jan 29, 2009, 11:05 PM
I have already tried what you have described but the background color is not changing. It may be that I am missing something in my custom cell that is restricting the same

dejo
Jan 30, 2009, 12:24 AM
I have already tried what you have described but the background color is not changing. It may be that I am missing something in my custom cell that is restricting the same
Are the subviews within your tableViewCell taking up the entire space of the cell? If so, they might be covering up the backgroundColor of the cell itself. Either set the backgroundColors of those subviews to clearColor (something Apple doesn't recommend) or set the backgroundColor of each subview.