How does UITableView.automaticDimension work?
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.