Reputation: 7560
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.
Upvotes: 23
Views: 8760
Reputation: 956
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()
}
}
Upvotes: 1
Reputation: 54
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;
Upvotes: 0
Reputation: 4722
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];
});
}
Upvotes: 0
Reputation: 290
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
Upvotes: 2