0
votes

I have set a UITableView's line separator style and colour in IB, however, when the table loads the separator lines are not visible.

I am using a UITableView which has a custom superclass CustomTableView - this is a subclass of UITableView. In this table, I am also using a custom UITableViewCell.

The only issue I could think it would be is if I didn't call the 'super' implementation in my awakeFromNib method - but I do this so it can't be that.

Any ideas?

EDIT with code

My table cell is as follows - CustomDefaultCell.h > CustomPlainCell.h > UITableViewCell

CustomDefaultCell.m

- (void)awakeFromNib
{
    [super awakeFromNib];

    // Called when loaded from a nib.
    // Override all default cell behaviour here.
    //
}

CustomPlainCell.m

- (void)awakeFromNib
{
    [super awakeFromNib];

    // Called when loaded from a nib.
    // Override all default cell behaviour here.
    //
    // Normal background view
    self.backgroundView = [[UIView alloc] initWithFrame:self.frame];
    self.backgroundView.backgroundColor = [UIColor whiteColor];

    // Selected background view
    self.selectedBackgroundView = [[UIView alloc] init];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
    //
    // Background gradient
    CAGradientLayer *selectedViewGradientLayer = [CAGradientLayer layer];
    selectedViewGradientLayer.frame = CGRectMake(1.0f, 0.0f, 320.0f, CGRectGetHeight(self.frame) + 1.0f);
    selectedViewGradientLayer.colors = @[(id)[UIColor colorWithHue:0.0f saturation:0.0f brightness:0.57f alpha:1.0f].CGColor, (id)[UIColor grayColor].CGColor];

    [self.selectedBackgroundView.layer addSublayer:selectedViewGradientLayer];
}
2
Are you using Quartz to draw your content? - user529758
I have a .xib file, with corresponding .h and .m - Adam Carter
I know, but what's in the .h and m.? (Don't tell me "there's code inside"!) - user529758
Sorry, just realised whata silly answer that was :P Edited with code - Adam Carter
oh yes, just as I thought! You are using Quartz to draw your cell's content. The solution: move all the setSelected method's code into drawRect:. - user529758

2 Answers

2
votes

Had the same problem and figured that I was not calling [super layoutSubviews]; when overriding that method in cell prototype class.

0
votes

Eventually I decided yo use the delegate method tableView:willDisplayCell:forRowAtIndexPath: and if the cell was a subclass of 'CustomPlainCell', add a 1pt high UIView with a background colour.