Reputation: 3404
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:
Then I have custom cell
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:
When I run with Swift4 settings in Xcode9 beta:
What would be the reason of this behavior?
Upvotes: 1
Views: 1226
Reputation: 56
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 30.0
Add this in your viewDidLoad
and no need of tableview delegate method estimatedHeightForRowAt
.
Upvotes: 3