iOS Table View Cell Separator Lines Not Showing

RagingGoat

macrumors 6502
Original poster
Jun 21, 2010
300
14
I've set the image for the cells in my table view but the lines dividing the cells aren't showing. What have I done wrong?

Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *mbTableIdentifier = @"SimpleTableItem";
    UIImageView *image = [[UIImageView alloc]init];
    image.image = [UIImage imageNamed:@"BarButton.png"];

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mbTableIdentifier];

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:mbTableIdentifier];
        cell.textLabel.font=[UIFont systemFontOfSize:16.0];
    }

    // cell.backgroundView = [[CustomCellBackground alloc] init];
    cell.selectedBackgroundView = [[CustomCellBackground alloc] init];
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.highlightedTextColor = [UIColor darkGrayColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.backgroundView = image;

    cell.textLabel.text = [mbTableData objectAtIndex:indexPath.row];
    return cell;
}
I can see the separator lines if I un-comment
Code:
cell.backgroundView = [[CustomCellBackground alloc] init];
I also logged the separator style and color

2013-05-19 21:38:21.103 KFBNewsroom[2593:c07] cell separator style: 2 separator color: UIDeviceRGBColorSpace 0.67 0.67 0.67 1
2013-05-19 21:38:21.104 KFBNewsroom[2593:c07] cell separator style: 2 separator color: UIDeviceRGBColorSpace 0.67 0.67 0.67 1
2013-05-19 21:38:21.105 KFBNewsroom[2593:c07] cell separator style: 2 separator color: UIDeviceRGBColorSpace 0.67 0.67 0.67 1
 

Attachments


blueillusion

macrumors member
Aug 18, 2008
51
0
Hm, perhaps post the code to CustomCellbackground?

Also, when setting a background view for a cell, you should normally not do it in cellForRowAtIndexPath, but rather in the willDisplayCell:ForRowAtIndexPath: method. There you should setup the cell colour/background view.
 

Duncan C

macrumors 6502a
Jan 21, 2008
853
0
Northern Virginia
Hm, perhaps post the code to CustomCellbackground?

Also, when setting a background view for a cell, you should normally not do it in cellForRowAtIndexPath, but rather in the willDisplayCell:ForRowAtIndexPath: method. There you should setup the cell colour/background view.
Background color, yes.

However, you should not add structural elements like background views to a cell in willDisplayCell. That gets called each time a table view is getting ready to display a cell.

CellForRowAtIndexPath gets called when cells are created/recycled. (Under the new approach in storyboards your cell prototypes build the custom cells, but that's another story)
 

blueillusion

macrumors member
Aug 18, 2008
51
0
Ah yes, I just doubled checked the method documentation, and you are absolutely right about that. Made me double check some of my code in my programs haha.
 

MattInOz

macrumors 68030
Jan 19, 2006
2,761
0
Sydney
As I understand it...
By setting your view as the background view you are removing the background view and the drawing it does. So the cell separators doesn't get drawn.

Try adding your view to the background view.