How does UITableView.automaticDimension work?

Sudhanshu Srivastava
1 min readAug 23, 2021
Photo by Pete Nuij on Unsplash

Self sizing cells are really amazing tool available for creating beautiful user experience.

To enable self-sizing cell’s in a tableView following lines are very commonly used

tableView.estimatedRowHeight = 100
tableView.rowHeight = UITableView.automaticDimension

But, what does these 2 lines mean and what is going behind the scene?

By setting tableView.rowHeight to UITableView.automaticDimension you are telling the system to calculate the cell’s height from the applied NSLayoutContraints and the intrinsic height of subviews in the given cell of tableView.

That means constraints should be perfectly assigned and shouldn’t break at all to help calculating accurate cell height. So, if you are facing issue with dynamic cell height event after using the above 2 lines then you have broken constraints for sure.

Now, tableView.estimatedRowHeight should given a value as near to accurate as possible that’ll help system to calculate height of scroll bar and hence helps in more seamless user experience.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Sudhanshu Srivastava
Sudhanshu Srivastava

Written by Sudhanshu Srivastava

I write about what I learn. Swift, Kotlin, Flutter, Social and Life.

No responses yet

Write a response