UITableViewAutomaticDimension not working on iOS 8

bluenowhere picture bluenowhere · Jan 4, 2016 · Viewed 14.1k times · Source

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:

enter image description here

iOS 9 as I expected:

enter image description here

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()

Answer

hasankose picture hasankose · Apr 19, 2016

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

    cell.setNeedsUpdateConstraints()
    cell.updateConstraintsIfNeeded()