UITableViewAutomaticDimension not working on iOS 8

table view automatic dimension not working
uitableview has no member uitableviewautomaticdimension
uitableview automatic dimension swift
uitableview dynamic cell height programmatically swift 4
heightforrowat dynamic swift
uitableviewcell not resizing
uitableview dynamic height // swift
uitableviewcell intrinsiccontentsize

I was following this tutorial to make self sizing cells.

I registered custom cell into table view and in the cell xib I gave every subview constraints manually. Please refer to the source code in GitHub

Arranging 3 labels vertically in one cell's content view worked fine in iOS 9 but not in iOS 8 (both tested in device and simulator).

In iOS 8 one cell does not have fitting height and not every label shows all it's full text.

iOS 8 not fitting:

iOS 9 as I expected:

Any advice would be appreciated!

Update

code in viewDidLoad:

 tableView.registerNib(UINib.init(nibName: "SelfSizingCell", bundle: nil), forCellReuseIdentifier: cellIdentifier)
 tableView.dataSource = self
 tableView.delegate = self
 tableView.estimatedRowHeight = 60.0
 tableView.rowHeight = UITableViewAutomaticDimension
 tableView.reloadData()

add following code in "cellForRowAtIndexPath" method before return cell.

    cell.setNeedsUpdateConstraints()
    cell.updateConstraintsIfNeeded()

UITableViewAutomaticDimension not working for footer in iOS8, After the test, here are my results. For iOS8, UITableViewAutomaticDimension only works for the section header and tableview cell and does not work for the  In the function set the cell with the preferred content, in order for UITableViewAutomaticDimension to work flawlessly. The problem is caused because the cell content is loaded in some other delegate function, so you can see that cells automatically resize to the required size.

To make it work on iOS 8 you need 3 things:

1) Set your table "estimated row height" on your view did load method.

tableView.estimatedRowHeight = 200.0

2) Implement the "table view height for cell at... method". (Remove the 'override' if your class is not a subclass of 'UITableViewController' and you are adding the table view yourself.

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

3) Call the 'updateConstraintsIfNeeded' method when you return your cell inside the 'table view cell for row at...' method.

cell.updateConstraintsIfNeeded()

return cell

Notice: Step 3 is NOT needed for iOS 9+

UITableViewAutomaticDimension is broken : iOSProgramming, This crap has been happening since iOS8 and frankly, I don't see it being fixed and while this certainly helps the problem, there are still jerky behaviors that  In order to make UITableViewAutomaticDimension work you have to set all left, right, bottom, and top constraints relative to cell container view. In your case you will need to add the missing bottom space to superview constraint for label under the title

Give Top,Bottom,Leading,Trailing Contraints to UILabel used. Check numberOfLine must be 0 Then set below methods

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewAutomaticDimension;}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewAutomaticDimension;}

Now run the project :)

why UITableViewAutomaticDimension not working?, I was following this tutorial to make self sizing cells. I registered custom cell into table view and in the cell xib I gave every subview constraints manually. Please  why UITableViewAutomaticDimension not working? (11) Hi there is plenty of question answering the dynamic height for UITableViewCell of UITableView. However I find it weird when I did it. here's are some of the answer : here and here

Version 10.1

UITableViewAutomaticDimension is renamed to UITableView.automaticDimension

UITableViewAutomaticDimension not working until |Apple , In order to make UITableViewAutomaticDimension work you have to set all added them to the cell directly, i.e. not on the contentView property. Questions: The iOS doc says that we can present one or 2 pages at a jquery – Angular 8 click is working as javascript onload function · javascript – window. UITableViewAutomaticDimension is broken Question I am not sure about how you guys typically build your UITableViews, but I have been building mine since iOS8 using dynamic heights, AKA, setting the rowHeight = UITableViewAutomaticDimension and using autolayout in the cell to determine the height at runtime.

This two lines did the trick for me:

tableView.estimatedRowHeight = 200.0
tableView.rowHeight = UITableViewAutomaticDimension

Everything else I tried from other answers didn't work.

Self Sizing Table View Cells, Since iOS 10 it seems that my cells are not properly sizing themselves until AFTER they are refreshed, either by scrolling or by doing a. Unfortunately automatic sizing of the cell height via UITableViewAutomaticDimension does not work consistently in iOS 8 and 9. Filed as rdar://22193223 and on OpenRadar. Tableview automatic dimension might truncate labels until first cell reuse

why UITableViewAutomaticDimension not working?, In the upcoming release of iOS 8 the Apple internal apps will adopt dynamic type Unfortunately if you build and run at this point it does not work. to what should be the default in iOS 8 - UITableViewAutomaticDimension . Since iOS 10 it seems that my cells are not properly sizing themselves until AFTER they are refreshed, either by scrolling or by doing a tableView.reloadData() in viewDidAppear (dosn't work in viewWillAppear, or viewDidLoad).

Understanding Self Sizing Cells and Dynamic Type in iOS 8, These are my constraint for title the title could be long but the label is not. and In order to make UITableViewAutomaticDimension work you have to set all left, left, and right edges of the content view (I used the respective constraints 8, 8, 15​  Common iOS 13 problems and how to fix them (iOS 13.5.1 update) By Jackie Dove June 9, 2020 Just when you thought iOS 13 was finally safe, along comes iOS 13.5.

In iOS 8, Apple introduces a new feature for UITableView known as Self Sizing Cells. view; Set the rowHeight of your table view to UITableViewAutomaticDimension But the problem was also mentioned by UseYourLoaf. This should work on iOS 8 as well as iOS 7. Note: tested using iOS 8.1 and 7.1, in my case I only needed to use the first step of this explanation. The Second Step is only required if you have unpopulated cell beneath the rendered cells, ie. if the table is larger than the number of rows in the table model.

Comments
  • Did you set tableView.estimatedRowHeight in viewDidLoad?
  • @robmayoff yup I did, I made no difference to my code when tested it on iOS 8 and iOS 9. Please check the GitHub link above.
  • I have to set specific height constraints for the upper 2 labels to make the height automation work in iOS8, or simply have no more than 2 labels in one cell. Looking for a better way ...
  • @bluenowhere Did you correct this problem ? I would like to know the solution as well. Please post an answer if you know. I am developing everything programmatically.
  • @Maven the comment below the accepted answer worked for me
  • What's causing this issue?
  • What is the reason of that? Thanks.
  • For Xamarin use: GetHeightForRow with return UITableView.AutomaticDimension and EstimatedHeight with return UITableView.AutomaticDimension
  • issue resolved. the problem was that I had set a fixed height for the title view of the tv cell... It seems that none of the view elements that have constraints directly with the tv cell's content view can have any fixed height constraint. That is straightforward for the collection view in the tv cell but in my opinion not so straightforward for the title view... Very important for the collection view: self.collectionView.translatesAutoresizingMaskIntoConstraints = true .
  • And since the collection view in the tv cell has scrolling switched off, I had created this extension to update its height every time the tv cell lays out it subviews: extension UICollectionView { func updateHeight() { let updatedHeight = self.collectionViewLayout.collectionViewContentSize.height if updatedHeight != self.frame.size.height { let frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: self.frame.size.width, height: updatedHeight) self.frame = frame } } }