Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing last separator of cell in table

People also ask

How do I remove a separator line in a table?

If you don't want to draw the separator yourself, use this: // Hide the cell separator by moving it to the far right cell. separatorInset = UIEdgeInsetsMake(0, 10000, 0, 0);

How to remove extra separator lines in a UITableView?

Add a Plain UIView to the Footer of the UITableView First, grab a plain UIView from the object browser, and drag it to the the footer position below all of your cell prototypes. It worked! The separator lines are gone.

Which code is correct for removing extra lines from tableView?

To eliminate extra separator lines from bottom of UItableview programmatically, just write down following two lines of code and it will remove extra separator from it. tableView. sectionFooterHeight = 0. f; tableView.


Swift 5 Version of top voted answer:

tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1))

It works even if the number of cells is dynamic.


One smart way to remove the separator from last cell is to add a plain view with height of 1 only.

tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 1)];

I solved this problem by moving the Separator out of the view, so that I cannot see it

if indexPath.row == settings.count-1{
    cell.separatorInset = UIEdgeInsets.init(
                              top: 0, left: 400, 
                              bottom: 0, right: 0)
}else{
    cell.separatorInset = .zero
}

This solution will remove the last separator in each section of grouped tables, without needing to subclass the table or the cells.

Works in iOS 8. (Probably works in iOS 6+).

Add the following to your delegate:

#pragma mark - UITableViewDelegate

- (CGFloat) tableView:(UITableView*)table
        heightForFooterInSection:(NSInteger)section {
     // Hide the separator when the table is first displayed
     // of any sections that are visible on the screen.
     [self hideBottomSeparator:table];

     return 0.01f; // Or whatever you already return.
}


- (void) scrollViewDidScroll:(UITableView*)table {
    // Hide separators that are visible after table scrolls.
    // Check that event did not come from other scrollers
    // in the table.
    if ([table isKindOfClass:UITableView.class]) {
         [self hideBottomSeparator:table];
    }
}

- (void) hideBottomSeparator:(UITableView*)table {
    for (UIView* cell in table.visibleCells) {
         [self removeBottomSeparatorFromCell:cell];
    }
}

- (void) removeBottomSeparatorFromCell:(UITableViewCell*)cell {
    for (UIView* view in cell.subviews) {
        if (view.frame.origin.x == 0 &&
                view.frame.origin.y > cell.frame.size.height - 2 &&
                view.frame.size.width == cell.frame.size.width &&
                view.frame.size.height < 2) {
            [view removeFromSuperview];
        }
    }
}

It works by removing any thin UIViews in the visible cells that are full width and at the bottom of the cell (it leaves the top separator visible).

To remove the top separator as well, comment out the origin.y check

If you want to remove the separator from a particular section(s) you would have to get the section numbers from the cells.

Note: because it removes separators by size (and position) alone, it could fail for non-default table (or cell) inset values, or if iOS changes the look of the separator. Also, it could fail if iOS is changed so that the separators are not subviews of the cells, in which case some more rigorous scanning would be required to find the separator views.

It relies on iOS adding the cells to the table before calling heightForFooterInSection:

Also, as above, it will remove all separators from a plain table.