Reputation: 725
How do I remove the lines indicated in the picture? I have tried the following suggestions and none of them have worked for me,
How do I remove the borders of a UITableView?
Remove separator line for only one cell
Hide separator line on one UITableViewCell
This is my current code in cellForRowAt
:
if (indexPath.row == place_sections[indexPath.section].rows.count - 1) {
cell.separatorInset.left = 1000
//cell.layer.borderWidth = 0
//cell.separatorInset = UIEdgeInsetsMake(0, 160, 0, 160);
}
if (indexPath.row == 0) {
cell.separatorInset.left = 1000
//cell.layer.borderWidth = 0
//cell.separatorInset = UIEdgeInsetsMake(0, 160, 0, 160);
// self.tableview.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: self.tableview.frame.width, height: 1))
}
Thank you
Upvotes: 5
Views: 8357
Reputation: 98
I have found a great approach to do especially in case of UITableViewStyleGrouped
Add this method inside table view cell class
- (void)layoutSubviews
{
[super layoutSubviews];
for (UIView *view in self. subviews) {
if ([view isEqual:self.contentView])
continue;
view. hidden = view.bounds.size.width == self.bounds.size.width;
}
}
You can make swift version easily if you want
Upvotes: 0
Reputation: 1212
Separator between header and cell belongs to first cell in section.
When I used standard UITableViewHeaderFooterView
and UITableViewCell
I managed to hide line between header and cell via this code:
let contentView = cell.contentView
if
// this separator is subview of first UITableViewCell in section
indexPath.row == 0,
// truing to find it in subviews
let divider = cell.subviews.filter({ $0.frame.minY == 0 && $0 !== contentView }).first
{
divider.isHidden = true
}
This piece of code must be invoked in tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
Upvotes: 3
Reputation: 725
The closest I could solve this problem is to change UITableView's Style from "Grouped" to "Plain".
I wouldn't recommend it if you can find a better solution because now the section headers stick to the top of the screen when scrolling, which is undesirable (I believe the proper way to describe this is "the section headers float").
Upvotes: 0
Reputation: 17912
This is objective c code, this help you
http://www.iostute.com/2015/04/expandable-and-collapsable-tableview.html
For both swift and objective c
http://www.anexinet.com/blog/expandable-collapsible-uitableview-sections/
The 1st link has custom header view, so border lines won't come here.
Comment this code in viewForHeaderInSection function
// /********** Add a custom Separator with Section view *******************/
// UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(15, 40, _expandableTableView.frame.size.width-15, 1)];
// separatorLineView.backgroundColor = [UIColor blackColor];
// [sectionView addSubview:separatorLineView];
Upvotes: 0