D4ttatraya
D4ttatraya

Reputation: 3404

Autolayout broken in Xcode-9 beta

I am having UITableView in my one of screens. It shows section headers and rows with dynamic height.
There are two issues with this set-up when I moved from Xcode8.3 to Xcode-9 beta.

1 Header view height broken
2 Dynamic height of rows broken

I have set-up my table view as:

enter image description here enter image description here

Then I have custom cell

enter image description here
enter image description here
enter image description here

Here is code:

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return //dynamically calculated height according to msg text
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 30
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
    let headerHeight:CGFloat = tableView.sectionHeaderHeight
    let headerView = HeaderView(frame: CGRect(x: 0, y: 0, width: tableView.width, height: headerHeight), withHeaderLable: "Date/Day of msg")
    return headerView
}

This works perfect in Xcode8.3 even with multiple lines of msgs, but broken in Xcode9 beta as: When I run with Swift3.2 settings in Xcode9 beta:

enter image description here

When I run with Swift4 settings in Xcode9 beta:

enter image description here

What would be the reason of this behavior?

Upvotes: 1

Views: 1226

Answers (1)

Swaroop Gs
Swaroop Gs

Reputation: 56

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 30.0

Add this in your viewDidLoad and no need of tableview delegate method estimatedHeightForRowAt.

Upvotes: 3

Related Questions