Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

arnieterm

macrumors regular
Original poster
Aug 28, 2008
201
0
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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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

macrumors regular
Original poster
Aug 28, 2008
201
0
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

macrumors regular
Original poster
Aug 28, 2008
201
0
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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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

macrumors regular
Original poster
Aug 28, 2008
201
0
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

Moderator emeritus
Sep 2, 2004
15,982
452
The Centennial State
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.