I set up a table view in Interface Builder, with Separator set to Single Line, and in the data source class I have this code:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.row == 0) { UIImageView *topCellBackgroundImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"grouped-cell-bg-top"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)]]; cell.backgroundView = topCellBackgroundImageView; } // If it's the last row else if (indexPath.row == ([tableView numberOfRowsInSection:0] - 1)) { UIImageView *bottomCellBackgroundImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"grouped-cell-bg-bottom"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)]]; cell.backgroundView = bottomCellBackgroundImageView; } else { UIImageView *middleCellBackgroundImageView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"grouped-cell-bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(3.0, 3.0, 3.0, 3.0)]]; cell.backgroundView = middleCellBackgroundImageView; } } And in viewDidLoad I do:
- (void)viewDidLoad { [super viewDidLoad]; self.tableView.separatorColor = [UIColor redColor]; self.tableView.backgroundView = nil; self.tableView.backgroundColor = [UIColor colorWithRed:245/255.0 green:244/255.0 blue:240/255.0 alpha:1.0]; } But the border color never shows up. I tried setting them in the images, but obviously that presents a lot of centering issues with the images, and having their borders overlap.
UPDATE:
After looking around a bit more, it does indeed get set, but it seems that setting the cell's backgroundView puts what you set as the backgroundView over the separatorColor. When I remove the willDisplayCell: method, the red color shows up fine (same when I select the cell even with the backgroundView set, it will show red until I unselect it). The question is, how can I set the separatorColor if I have a backgroundView set?
self.tableViewis not nil, right? Maybe try putting a breakpoint somewhere and printing the value in your console to see if something changed it somehow?willDisplayCell:method, the red color shows up fine (same when I select the cell even with the backgroundView set, it will show red until I unselect it). The question is, how can I set the separatorColor if I have a backgroundView set?