user5483739
user5483739

Reputation:

How to remove cell separators in UITableView?

I want to remove the cell separators in my UITableView. This is how my simulator currently looks:

enter image description here

I have implemented the following line of code in the viewDidLoad: method of the .swift file of the view controller:

self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None

This doesn't seem to be working though.

How do I remove the cell separators?

Here is my cellForRowAtIndexPath: code:

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

        // Configure the cell...
        cell.nameLabel.text = restaurants[indexPath.row].name
        cell.typeLabel.text = restaurants[indexPath.row].type
        cell.mainImageView.image = UIImage(named: restaurants[indexPath.row].image)

    return cell

}

Upvotes: 3

Views: 2645

Answers (3)

Lumialxk
Lumialxk

Reputation: 6369

  1. Check your layout of cell,especially top and bottom constraints.enter image description here
  2. Check the content view of cell.Did you set the clips to bounds to true?enter image description here enter image description here

All the above should be checked both in code and IB.

Upvotes: 2

MKoosej
MKoosej

Reputation: 3696

I suggest giving the cells a random background color instead of white so you can make sure the cell has padding and it's not part of image. If it didn't work you may try setting the inset to zero using both the table and cell reference. Look at this answer for more explanation.

Remove SeparatorInset on iOS 8 UITableView for XCode 6 iPhone Simulator

Upvotes: 0

adrianokw
adrianokw

Reputation: 389

To hide the separator line you should set the separator insets to zero for each cell. You should add this line in your cellForRowAtIndexPath:

cell.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)

Upvotes: 0

Related Questions