5

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

enter image description here

degenPenguin
  • 725
  • 1
  • 8
  • 23
  • Have you tried setting `tableView.separatorColor = tableView.backgroundColor`? It wont remove the separator, but it should work out since you simply want visible results only – Skywalker Jan 11 '18 at 03:43
  • Read comment to the first answer below. This is not quite what I am looking for. – degenPenguin Jan 11 '18 at 06:45
  • @marko calvocruz I understood your problem, I will try to solve it... – Naresh Jan 11 '18 at 06:57

3 Answers3

3

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)

Konstantin Berkov
  • 1,193
  • 3
  • 14
  • 27
0

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];

See the screen shot enter image description here

Naresh
  • 16,698
  • 6
  • 112
  • 113
  • The issue is I would like to keep the separators between rows. I just do not like the separator between the (last row & the section header) and (section header & first row). – degenPenguin Jan 11 '18 at 06:44
  • @iOSDeveloper he wants to keep the separator between cells. Not the one between cells and section headers.. – Skywalker Jan 11 '18 at 06:53
  • After checking out both of these links, neither really help me with the problem I am having. – degenPenguin Jan 11 '18 at 19:26
  • This solution removes separator from not only header but also last cell of each section. This is inconsistent behavior in respect to user experience and I guess even that is not what is expected in the question as well. – Tejas Apr 06 '20 at 08:41
0

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").

UItableview Grouped

degenPenguin
  • 725
  • 1
  • 8
  • 23