I have a UITableView
that is set to not enable scrolling, and it exists in a UIScrollView
. I'm doing it this way as the design specs call for something that looks like a tableView
. The TableView
Cell having dynamic height So I use
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Now once I fetched data from API and before Reloading TableView.
I update height constraint of both tableView
and ScrollView
. But height does not get update. I used the below code
self.view.layoutIfNeeded()
tvHeightConstraint.constant = tvPrdtDetail.contentSize.height
svHeightConstraint.constant = tvPrdtDetail.contentSize.height + 8
Here tvHeightConstraint
and svHeightConstraint
are height constraint of tableView
and ScrollView
@IBOutlet weak var tvHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var svHeightConstraint: NSLayoutConstraint!
Log always show 0 when I print TableView
ContentSize
print("Content Size: \(tvPrdtDetail.contentSize.height)")
Please help me out . Thanks in advance.
Try this hope so this will work.Call this when you need constraint should update,And
override updateConstraints
function