Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TableView Seperator line gets added to the section header view, what to do?

I got a table view with two sections, no crazy code, just my delegate methods. It works pretty fine, like i want it to work. It should just look like on this screenshot:

enter image description here

Now the problem is: Sometimes while scrolling or flicking the scoll view to the bounds, this happens (if you can't see it: There is 1 or 1/2 pixel in gray on the top of the second section header, what is not intended to be so):

enter image description here

So, is this a iOS 7.1 or 7.x bug? I'm not using a custom view for the header. Does anyone know how to fix this?

Feedback really is appreciated.

like image 280
user3083408 Avatar asked Mar 20 '14 17:03

user3083408


1 Answers

I had this same problem that I battled for a few weeks, and the way I solved it was to set the tableView's separatorStyle to UITableViewCellSeparatorStyleNone, and add a custom subview that is a line to the cell's contentView.

Then in your cellForRowAtIndexPath method, hide the line subview of the last cell in the section:

- (UIView *)lineView
{
    // Your frame will vary.
    UIView *colorLineView = [[UIView alloc]initWithFrame:CGRectMake(82, 67.5, 238, 0.5)];
    colorLineView.backgroundColor = [UIColor blackColor];
    return colorLineView;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    static NSString *identifier = @"cellIdentifier";
    UIView *lineView = [self lineView];

    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    if (cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleDefault;

        [cell.contentView addSubview:lineView];
    }

    if (indexPath.section == 0)
    {   
        if (indexPath.row == keys.count -1)
        {
            lineView.hidden = YES;
        }
    }
    return cell;
}
like image 126
klcjr89 Avatar answered Nov 10 '22 00:11

klcjr89