Why doesn't separator inset 0 work in iOS 8? Getting to know the problem
\n\nImagine: 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?
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\nIf 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\nThe root of the evil: what is separatorInset and why does iOS 8 ignore it?
\n\nBefore 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.
When you write:
\n\ncell.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
separatorInsetproperty on the cell doesn't always override the table's global settings. \n - Reason 2: There is a "magical" property called
layoutMarginsthat takes priority overseparatorInsetin 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
In short: you tell the cell "set the margin to 0", and it replies "no, I obey the table and its layoutMargins".
\n\nStep-by-step solution: how to make separator inset work in iOS 8
\n\nHere is a proven recipe that worked in iOS 8 and still works today. We'll act on three levels: table → cell → layoutMargins.
\n\nStep 1. Configuring UITableView (global level)
\n\nThe most reliable way is to set the margins for the entire table at once, in viewDidLoad:
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\nThese three lines are your basic protection. But sometimes this isn't enough, and you need to fine-tune at the cell level.
\n\nStep 2. Configuring each cell (local level)
\n\nIn the cellForRowAt method, add:
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\nNote: we are duplicating the settings. This is not a mistake — this way we guarantee that the cell overrides any global table settings.
\n\n