bwash70 bwash70 - 2 months ago 18
iOS Question

Swift Tableview always showing separator lines

I seem to have a weird problem with one of my tableviews where I can't hide the separator lines ( I think they're separator lines, except that they're centred on the screen instead of hard up against the right hand side ).

I create everything programmatically so no storyboard issues here.

You can see the tiny 1px line above each of the cells below.

Screenshot of issue

I load my table using:

self.tableView.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
self.tableView.dataSource = self
self.tableView.delegate = self
self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
self.tableView.backgroundColor = UIColor.whiteColor()
self.tableView.scrollEnabled = true
self.tableView.bounces = false
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None

I also have a custom header which I implement using the following code:

func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {

let header:UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView

header.textLabel.textColor = UIColor.whiteColor()
header.textLabel.frame = header.bounds
header.textLabel.textAlignment = NSTextAlignment.Center

view.tintColor = constants.getTintColor()
header.textLabel.textColor = UIColor.whiteColor()


I've tried loading the table without the
and the issue persists.

I have also tried adding

tableview.separatorStyle = UITableViewCellSeparatorStyle.None


tableView.separatorColor = UIColor.clearColor()

to the following methods:

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

tableView.separatorStyle = UITableViewCellSeparatorStyle.None


func numberOfSectionsInTableView(tableView: UITableView) -> Int {

tableView.separatorStyle = UITableViewCellSeparatorStyle.None

return self.boards.count

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
tableView.separatorStyle = UITableViewCellSeparatorStyle.None

return self.boards[section].items.count

func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String?
tableView.separatorStyle = UITableViewCellSeparatorStyle.None

return self.boards[section].name


The cells are standard UITableViewCells with alternating colors for the cells, this is being set through:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell

let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! UITableViewCell

cell.selectionStyle = UITableViewCellSelectionStyle.None

if indexPath.row % 2 == 0 {
// Even
cell.backgroundColor = constants.UIColorFromRGB(0x1EACE0)
} else {
// Odd
cell.backgroundColor = constants.UIColorFromRGB(0x6FBEE5)

cell.textLabel?.textColor = UIColor.whiteColor()
cell.textLabel?.text = self.boards[indexPath.section].items[indexPath.row].title

return cell


I've now added separator lines in and these aren't separators because you can still see them below the separator line.

enter image description here

HELP! I'm confused. I have a number of other tableviews setup the same (as far as I can see) and they work fine.

Thanks SO!


Since you are not using custom cell's you need to do the following.

Create cell's as let cell : UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Subtitle, reuseIdentifier:"cell")

and remove self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")