iOS 8 UITableView separator inset 0 not working: A Complete Guide for Beginners

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Why doesn't separator inset 0 work in iOS 8? Getting to know the problem

\n\n

Imagine: you're writing your first iPhone app, the table looks great on the iOS 14 simulator, but when you test it on an old iPhone 6 with iOS 8… bam! The cell separators behave unpredictably. You set separatorInset = .zero, but the left margins still remain. Sound familiar?

\n\n

This problem — iOS 8 UITableView separator inset 0 not working — is a real "stumbling block" for beginner iOS developers. On Stack Overflow, this question has gathered thousands of views, and for good reason. In this article, we won't just give you a ready-made solution; we'll also understand why this happens and how to avoid similar pitfalls in the future.

\n\n

If you're just starting to learn Swift and UIKit, don't worry — we'll go through the entire process step by step. By the end of the article, you won't just fix the bug, but you'll also understand how UITableView works at a deep level.

\n\n

The root of the evil: what is separatorInset and why does iOS 8 ignore it?

\n\n

Before treating, we need to understand the diagnosis. SeparatorInset is a property of UITableViewCell (and the table itself) that controls the margins of the separator line between cells. By default, iOS adds a small left margin (15 points) so the separator doesn't start right from the edge of the screen.

\n\n

When you write:

\n\n
cell.separatorInset = UIEdgeInsets.zero
\n\n

…you expect the line to go from edge to edge. But in iOS 8 (and earlier versions), this doesn't happen. Why?

\n\n
    \n
  • Reason 1: In iOS 8, the separatorInset property on the cell doesn't always override the table's global settings.
  • \n
  • Reason 2: There is a "magical" property called layoutMargins that takes priority over separatorInset in iOS 8. Apple didn't document this behavior, and many developers got caught out.
  • \n
  • Reason 3: The system adds margins by default via preservesSuperviewLayoutMargins, which is always enabled in iOS 8.
  • \n
\n\n

In short: you tell the cell "set the margin to 0", and it replies "no, I obey the table and its layoutMargins".

\n\n

Step-by-step solution: how to make separator inset work in iOS 8

\n\n

Here is a proven recipe that worked in iOS 8 and still works today. We'll act on three levels: table → cell → layoutMargins.

\n\n

Step 1. Configuring UITableView (global level)

\n\n

The most reliable way is to set the margins for the entire table at once, in viewDidLoad:

\n\n
override func viewDidLoad() {\n    super.viewDidLoad()\n    \n    // Disable extra margins for the table\n    tableView.separatorInset = .zero\n    tableView.layoutMargins = .zero\n    \n    // Important for iOS 8: prevent cells from inheriting margins from the table\n    tableView.preservesSuperviewLayoutMargins = false\n}
\n\n

These three lines are your basic protection. But sometimes this isn't enough, and you need to fine-tune at the cell level.

\n\n

Step 2. Configuring each cell (local level)

\n\n

In the cellForRowAt method, add:

\n\n
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)\n    \n    // Override cell settings\n    cell.separatorInset = .zero\n    cell.layoutMargins = .zero\n    cell.preservesSuperviewLayoutMargins = false\n    \n    // Configure content\n    cell.textLabel?.text = "Row \\(indexPath.row)"\n    \n    return cell\n}
\n\n

Note: we are duplicating the settings. This is not a mistake — this way we guarantee that the cell overrides any global table settings.

\n\n

Step 3. (Optional)

Blogs

Book Recommendations