6

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.

user3083408
  • 335
  • 1
  • 4
  • 11
  • Hi - please remember that people decide whether to read your question or not based on the title, and it is not overly descriptive :) You might get better response if you edit your question with a more descriptive title. – Monolo Mar 20 '14 at 18:21

3 Answers3

2

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;
}
klcjr89
  • 5,862
  • 10
  • 58
  • 91
  • 1
    Thanks for your answer, but that's not what i searched for. It for sure fixes the issue i have, but i aim to find a cleaner version which leaves the table view like it should be. – user3083408 Mar 20 '14 at 18:44
  • What's not 'clean' about it? You make no sense at all. – klcjr89 Mar 20 '14 at 19:59
  • It isn't clean because the seperator style shouldn't be changed. See my answer to my question and you see what i meant by clean. – user3083408 Mar 20 '14 at 20:08
  • Shouldn't according to who? As developers we have to work around Apple's shortcomings. Your implementation is actually worse. – klcjr89 Mar 20 '14 at 20:22
  • Shouldn't according to me, cause i wrote this question and i wanted it to be answered like i want, alright? Worse? That kinda hard being told from a man who's just replacing the seperators in a dirty way. – user3083408 Mar 21 '14 at 07:11
0

It may be recycling one of the cell views with the separator from the scroll. This is a long shot, but what if you were to try tweaking the footer view for the section by returning an empty view?

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] init];
}

It's also a good trick for removing empty cells from the table when you have only a couple rows.

Cameron
  • 1,142
  • 8
  • 32
  • Yeah, the line which gets added is indeed the seperator from the cell. But your solution won't fix anything, sorry. Thanks for your answer. – user3083408 Mar 20 '14 at 18:08
  • No worries - I figured it was a stretch, anyway. I think @troop231 might actually have the correct approach for what you want to do. Sometimes the little hacks are the only way to fix minutia. – Cameron Mar 20 '14 at 20:07
  • I answered my own question with the right apporoach (without modified seperators). – user3083408 Mar 20 '14 at 20:11
0

I tried it with multiple different things and the cleanest approach i found is this. I created a custom view for the header, but wanted it to look the same as the original not modified header:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 34)];
    [headerView setBackgroundColor:[UIColor groupTableViewBackgroundColor]];

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, 0, tableView.frame.size.width, 34)];
    [label setFont:[UIFont boldSystemFontOfSize:14]];

    if (section == 0) {
        NSMutableArray *difficultyArray = [dictionary objectForKey:@"Difficulty"];
        NSString *difficulty = [difficultyArray objectAtIndex:0];
        [label setText:[NSString stringWithFormat:@"Time Challenge (%@)", difficulty]];
    } else {
        [label setText:@"Freeplay (5x5 board)"];
    }

    [headerView addSubview:label];

    return headerView;
}

Now we got the sections as they would appear without custom header views, but the bug still exists. I made it simple and clean:

UIView *lineFix = [[UIView alloc] initWithFrame:CGRectMake(0, 77.5, self.tableView.frame.size.width, 0.5)];
lineFix.backgroundColor = [UIColor groupTableViewBackgroundColor];
[self.tableView addSubview:lineFix];

Now we set a view over the buggy seperator with a height of 0.5 pixel, the seperator isn't visible anymore. Between the two section headers now is a 0.5 height view what shouldn't be there, but since i set it the same color as the section background color it isn't noticeable. The view moves, because it is a subview of the tableview, the same direction like the tableview.

If you have questions, just add a comment.

user3083408
  • 335
  • 1
  • 4
  • 11