Tricky
Tricky

Reputation: 7155

Is there a way to remove the separator line from a UITableView?

I'm looking for a way to completely remove the separator line in a UITableView when in the plain mode. This is done automatically in grouped, but this also changes the dimensions of the table in a way that is hard to measure. I have set the seperator line color to colorClear. But this does not completely solve the problem.

As I am trying to draw a custom background view in the cells, and I want the cells to be seamless, the one pixel line that remains in-between is causing me problems. Is there a more elegant workaround then using a grouped view and then stretching it?

Upvotes: 228

Views: 126548

Answers (9)

Bart Jacobs
Bart Jacobs

Reputation: 9082

You can do this with the UITableView property separatorStyle. Make sure the property is set to UITableViewCellSeparatorStyleNone and you're set.

Objective-C

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

In Swift (prior to 3)

tableView.separatorStyle = .None

In Swift 3/4/5

tableView.separatorStyle = .none

Upvotes: 456

Mohsin Qureshi
Mohsin Qureshi

Reputation: 1213

In interface Builder set table view separator "None"

enter image description here and those separator lines which are shown after the last cell can be remove by following approach. Best approach is to assign Empty View to tableView FooterView in viewDidLoad

self.tableView.tableFooterView = UIView()

Upvotes: 10

Siddhesh Mahadeshwar
Siddhesh Mahadeshwar

Reputation: 1611

There is bug a iOS 9 beta 4: the separator line appears between UITableViewCells even if you set separatorStyle to UITableViewCellSeparatorStyleNone from the storyboard. To get around this, you have to set it from code, because as of now there is a bug from storyboard. Hope they will fix it in future beta.

Here's the code to set it:

[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

Upvotes: 5

Ashu
Ashu

Reputation: 3523

In the ViewDidLoad Method, you have to write this line.

tableViews.separatorStyle = UITableViewCellSeparatorStyleNone;

This is working Code.

Upvotes: 2

Aatish Javiya
Aatish Javiya

Reputation: 71

In your viewDidLoad:

self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)])
{
    [self.tableView setSeparatorInset:UIEdgeInsetsZero];
}

Upvotes: 1

Mohsen
Mohsen

Reputation: 65775

In Swift:

tableView.separatorStyle = .None

Upvotes: 9

Kevin DiTraglia
Kevin DiTraglia

Reputation: 26048

You can do this in the storyboard / xib editor as well. Just set Seperator to none.

enter image description here

Upvotes: 64

Sig Myers
Sig Myers

Reputation: 371

I still had a dark grey line after attempting the other answers. I had to add the following two lines to make everything "invisible" in terms of row lines between cells.

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.separatorColor = [UIColor clearColor];

Upvotes: 18

imthi
imthi

Reputation: 4798

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}

Upvotes: 62

Related Questions