UITableView separators don't show after changing table background color

Discussion in 'iOS Programming' started by straber, Feb 18, 2013.

  1. straber macrumors member

    Joined:
    Jul 3, 2012
    #1
    I have a UITableView, and when I set its background color to gray, the separator between the cells doesn't show. The separator color is set to white, and if I don't change the table's background color, the separators show up fine. Does anyone know why this is or how to fix it?

    Thanks in advance...
     
  2. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #2
    If you're using code to set this all up, lets see it. If your are using the IB editor, then post the details via image captures.
     
  3. straber thread starter macrumors member

    Joined:
    Jul 3, 2012
    #3
    This code is in the UITableViewController

    in viewDidLoad:

    Code:
    self.tableView.separatorStyle  = UITableViewCellSeparatorStyleSingleLineEtched;
        self.tableView.separatorColor  = [UIColor whiteColor];
        self.tableView.backgroundColor = [UIColor colorWithRed:230.0 / 255.0 green:230.0 / 255.0 blue:230.0 / 255.0 alpha:1.0];
    and in tableView: cellForRowAtIndexPath

    Code:
    cell.contentView.backgroundColor = [UIColor colorWithRed:230.0 / 255.0 green:230.0 / 255.0 blue:230.0 / 255.0 alpha:1.0];
        cell.textLabel.backgroundColor = [UIColor clearColor];
    If I don't change the background color of the table, everything below the last cell is white, but the separators show, if I do change the background color, everything is the same color, but the separators don't show.
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    Have you tried setting the backgroundColor before setting the separatorColor?
     
  5. straber thread starter macrumors member

    Joined:
    Jul 3, 2012
    #5
    Yes, I did try that with no luck. The separators still didn't show.
     
  6. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #6
    Alright, thought it was worth a shot. Thanks for trying.
     
  7. straber thread starter macrumors member

    Joined:
    Jul 3, 2012
    #7
    The issue seems to be that the backgroundColor property overrides the separatorColor property because regardless of what I set the separatorColor to, the separator lines end up being whatever color I set the backgroundColor to. I was setting the backgroundColor to the same color as my table cells so that the area under the last cell would be the same color, but this was making the separators the same color as the table cells, giving the appearance that they weren't there.
     
  8. xStep macrumors 68000

    Joined:
    Jan 28, 2003
    Location:
    Less lost in L.A.
    #8
    UITableViewCellSeparatorStyleSingleLineEtched is "currently only supported for grouped-style table views". Try UITableViewCellSeparatorStyleSingleLine in it's place.

    Also, given the code you mentioned, you should not need the two lines in the cellForRowAtIndexPath: method.
     

Share This Page