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

straber

macrumors member
Original poster
Jul 3, 2012
60
0
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...
 

straber

macrumors member
Original poster
Jul 3, 2012
60
0
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.
 

straber

macrumors member
Original poster
Jul 3, 2012
60
0
Yes, I did try that with no luck. The separators still didn't show.
 

straber

macrumors member
Original poster
Jul 3, 2012
60
0
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.
 

xStep

macrumors 68020
Jan 28, 2003
2,031
143
Less lost in L.A.
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.