Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewAutomaticDimension not working on iOS 8

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()
like image 628
bluenowhere Avatar asked Jan 04 '16 03:01

bluenowhere


1 Answers

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

    cell.setNeedsUpdateConstraints()
    cell.updateConstraintsIfNeeded()
like image 98
hasankose Avatar answered Nov 15 '22 09:11

hasankose