mihatel
mihatel

Reputation: 846

Swift UITableView separator not visible

I'm new in ios/swft and faced with problem showing separator in table view. I've spent already few days tried out almost all suggestions none of them works for me. I'm inserting cells dynamically and in this case separator disappears. Below the code I'm using.

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var tableView: UITableView!

    let tableData = ["One","Two","Three"]


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        tableView.delegate = self
        tableView.dataSource = self
    }


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return tableData.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("Cell")!

        cell.textLabel?.text = tableData[indexPath.row]
        return cell
    }

}

On a storyboard it is simple tableview on a view, nothing special.

This is really annoying me, please help to fix it.

Upvotes: 5

Views: 9489

Answers (3)

Ali Qaderi
Ali Qaderi

Reputation: 471

I know this is late but may be help someone in Swift 4:

override func viewDidLoad() {
super.viewDidLoad()

tableView.delegate = self
tableView.dataSource = self
tableView.separatorStyle = UITableViewCellSeparatorStyle.singleLine
tableView.separatorColor = UIColor.YourColor
tableView.separatorInset = UIEdgeInsetsMake(0, 5, 0, 5)
}

Upvotes: 2

mihatel
mihatel

Reputation: 846

It turned out that issue is only on the simulator, not on an actual device.

Upvotes: 10

Michael Dautermann
Michael Dautermann

Reputation: 89559

try this:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    tableView.delegate = self
    tableView.dataSource = self
    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine
    tableView.separatorColor = UIColor.grayColor()
}

If this doesn't work, you should edit your question to show (the code of) HOW you are inserting new cells into your table.

Upvotes: 3

Related Questions