23

I know this question has been asked before. But no person on the internet had a working and sufficient answer.

EDIT Obviously people don't read questions anymore, on SO. So I'm trying to clarify: I want to remove the SEPARATOR. The separator is neither the space above the section, nor the tableViewHeader or tableViewFooterView. It is only the thin line above (fully from left to right).

I have a grouped UITableView (I don't want to use a plain styled for many other reasons, take it as it is) which has multiple groups.

The first section should not have the separator line on top. Setting the separator style of the tableView is not an option, because I do need the other separators.

Setting the tableViews tableFooterView is something I often read, but it never worked.

I used the tableView with static content before and I was able to remove the separator in -[UITableViewController viewDidLoad] using this:

- (void)viewDidLoad { [[[self headerTableCell] valueForKey:@"_topSeparatorView"] removeFromSuperView]; } 

Since I now had to change the tableView to a dynamic one, the IBOutlet property won't work anymore (obviously).

So I tried everything, -[id tableView:willDisplayCell:atIndexPath:], -[UITableViewCell initWithStyle:reuseIdentifier:, prepareForReuse, awakeFromNib] and some others.

In any case, this separator is nil. So I need a method that gets called when the complete view hierarchy of the cell is setup.

7
  • 1
    A screenshot can take you a long way ;) Commented May 18, 2016 at 5:15
  • Did you find the answer since 2015 by chance? I am facing the same issue atm. Commented Aug 9, 2017 at 12:34
  • It's not possible. Commented Aug 9, 2017 at 18:24
  • @iur I ended up implementing custom view based cells. Commented Aug 22, 2017 at 17:02
  • Thank you for responding. In my case I had to agree to keep them :( Commented Aug 23, 2017 at 9:02

4 Answers 4

2

what i get from your situation you have a grouped UITableView you want the first section without separator and you want to keep the separator in the other sections so remove the separator from the whole tableview from the attributes inspector make Separator : None create custom UITableviewCell in storyboard for other sections and add View at the end of it with height 1 and width the whole screen (like default separator) it's maybe not the best idea but this will allow you to have the first section without separator

Sign up to request clarification or add additional context in comments.

Comments

1

add this override function in your Custom Cell Class

 override func layoutSubviews() { super.layoutSubviews() for subview in subviews where (subview != contentView && abs(subview.frame.width - frame.width) <= 0.1 && subview.frame.height < 2) { subview.removeFromSuperview() } } 

2 Comments

Hey Imran, thanks for your answer. It's been 6 years... I'd need to recreate the issue but sounds like a workable solution.
The only issue I see is cell reuse. You delete a subview, thus it wouldn't be there if the cell is reused in another section. I think I ended up creating a custom view all together, but it were a bit different times back then ;-)
0

I faced a similar problem, wanted to remove the last line of the section in grouped table view, I am calling following method in view will appear and on every table reload. This is not the exact answer but problem can be solved by just changing y value of dummy view.

+(void)removeLastSectionSeparatorForTableView:(UITableView *)tableView { UIView *oldSeparatorView = [tableView viewWithTag:kTagDummySectionSeparator]; if (oldSeparatorView != nil) { [oldSeparatorView removeFromSuperview]; } dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ UIView *view = [[UIView alloc] init]; view.tag = kTagDummySectionSeparator; view.backgroundColor = [UIColor colorWithRed:239.0/255 green:239.0/255 blue:244.0/255 alpha:1.0];//Group table background color view.frame = CGRectMake(0, tableView.contentSize.height-40, tableView.bounds.size.width, 2); [tableView addSubview:view]; }); } 

Comments

0

Maybe this problem is the same as mine before. Finally, my way to solve this problem: set table view delegate's method (CGFloat)tableView:(UITableView *)tableView heightForHeaderAtSection:(NSInteger)section, then return CGFLOAT_MIN;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.