custom UITableViewCell selectedCell color setting

Discussion in 'iPhone/iPad Programming' started by arnieterm, Jan 16, 2009.

  1. macrumors regular

    Joined:
    Aug 28, 2008
    #1
    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
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    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:
    If not, I would suggest looking at UITableViewCell's selectedBackgroundView property and adjusting the backgroundColor through it.
     
  3. thread starter macrumors regular

    Joined:
    Aug 28, 2008
    #3
    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
     
  4. thread starter macrumors regular

    Joined:
    Aug 28, 2008
    #4
    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
     
  5. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #5
    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.
     
  6. thread starter macrumors regular

    Joined:
    Aug 28, 2008
    #6
    Answer to your first question:
    UIView
     
  7. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Correct. And is there a property of UIView that may relate to it's background color?
     
  8. thread starter macrumors regular

    Joined:
    Aug 28, 2008
    #8
    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
     
  9. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #9
    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.
     

Share This Page