Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView displays separator at wrong position in iOS8 for some cells

Tags:

We have a UITableView and it was working fine for iOS7 but when I tried in the iOS8 simulator, I saw the cell separator was placed incorrectly for most cells. Strangely, some cells display the separator correctly.

See the attached image:

UITableView with wrong separator... sometimes!

I set the cell height this way:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70.0f;
}

Do you know what's happening? Thanks!

EDIT:

A workaround I'm using in the meantime is to disable the separator...

    [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

...and paint it myself in the cell view...

    UIView* separator = [[UIView alloc] initWithFrame:CGRectMake(20, cellHeight-1, frame.size.width - 40, 1)];
    separator.layer.borderWidth = 1;
    separator.layer.borderColor = [[UIColor grayColor] CGColor];
    [self addSubview:separator];

...but I'd like not to do it.

like image 688
Ferran Maylinch Avatar asked Sep 20 '14 09:09

Ferran Maylinch


1 Answers

I had the same problem and here is how I solved it:

If you are using a custom cell for your table view and you have overridden layoutSubviews, you need to call it's superview's method at the beginning of the method:

- (void)layoutSubviews
{
    [super layoutSubviews];
    // Your implementation
}
like image 149
Dijam Avatar answered Oct 13 '22 00:10

Dijam