UITableViewAutomaticDimension
iOS development
Swift
auto layout issues
UITableView troubleshooting

why UITableViewAutomaticDimension not working?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

UITableView.automaticDimension works only when Auto Layout can fully determine the cell's height. If the cell's content is missing constraints, has conflicting constraints, or still relies on fixed height assumptions, the table view has nothing reliable to measure.

That is why the fix is usually not a magic table-view setting. The fix is making the cell's layout complete from top to bottom and giving the table view enough information to estimate row height efficiently.

Start With The Required Table View Settings

At minimum, the table view should be configured like this:

swift
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 80

Without estimatedRowHeight, scrolling performance and initial layout behavior can become erratic. Without automaticDimension, the table view will not ask Auto Layout to calculate dynamic heights at all.

The Cell Needs A Full Vertical Constraint Chain

The most common cause of failure is that the cell's subviews do not form a complete vertical chain from the top of contentView to the bottom of contentView.

For example, a multi-line label inside the cell should have constraints like:

swift
1titleLabel.translatesAutoresizingMaskIntoConstraints = false
2contentView.addSubview(titleLabel)
3
4NSLayoutConstraint.activate([
5    titleLabel.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 12),
6    titleLabel.leadingAnchor.constraint(equalTo: contentView.leadingAnchor, constant: 16),
7    titleLabel.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16),
8    titleLabel.bottomAnchor.constraint(equalTo: contentView.bottomAnchor, constant: -12)
9])

If the bottom anchor is missing, Auto Layout cannot infer the final height.

Multiline Labels Need Correct Configuration

If a label is supposed to grow vertically, it also needs:

swift
titleLabel.numberOfLines = 0

Without that, the label may stay one line tall and the cell height will not expand. The label can still have valid constraints and yet not behave dynamically if the label itself is configured to stay on one line.

Avoid Fixed Height Constraints

Another common issue is accidentally pinning a subview or the cell with a fixed height constraint that fights the natural Auto Layout size. If the cell or one of its major subviews has an explicit height, automaticDimension has much less freedom to adapt.

This is especially easy to do in storyboards where an old fixed height was left behind while the developer expected the table to become dynamic automatically.

Use contentView, Not The Cell Root View

Constraints for dynamic content should generally attach to contentView, not to the cell itself. This matters because the table view measures the cell's content using contentView as the main layout surface.

Mixing constraints directly on the cell root can produce ambiguous or surprising layouts, especially with accessory views and separators.

Reload Or Recalculate After Content Changes

If the text or image content changes after the cell was first laid out, the table view may need a layout update:

swift
tableView.beginUpdates()
tableView.endUpdates()

This forces the table view to recalculate row heights. It is useful when asynchronous content changes the intrinsic size after the cell is already visible.

Debug Auto Layout, Not Just Table View Code

When automaticDimension fails, the best debugging tool is often Auto Layout itself. Look for:

  • missing bottom constraints
  • ambiguous vertical compression
  • fixed heights that should be dynamic
  • labels still set to one line
  • unsatisfiable constraint logs in the console

The table view is usually innocent. It is just revealing that the cell's layout rules are incomplete.

Common Pitfalls

One common mistake is setting automaticDimension but forgetting estimatedRowHeight. Another is constraining subviews without a full top-to-bottom chain through contentView. Developers also often forget numberOfLines = 0 on labels that are expected to wrap. Finally, asynchronous content updates can make the initial cell height look wrong until the table view is told to recompute the layout.

Summary

  • Set rowHeight to UITableView.automaticDimension and provide an estimatedRowHeight.
  • Make sure the cell's subviews form a complete vertical constraint chain inside contentView.
  • Configure labels for multiline growth when needed.
  • Remove accidental fixed-height constraints that fight dynamic sizing.
  • If content changes after initial layout, trigger a height recalculation with a table view update pass.

Course illustration
Course illustration

All Rights Reserved.