Uitableview inside scrollview dynamic height update not working iOS swift
Problem:
I'm having scrollview with it's it had some views inside scrollview as well as one tableview is inside scrollview.Tableview had dynamic height based on the api response.
I had updated the height based on the scroll content but it was not working.How to solve that?
Solution:
Because you must have to set the dynamic height in viewdidlayoutsubviews.Also call the height update in will display cell tableview delegate method.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
self.viewDidLayoutSubviews()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
self.tableview.layoutIfNeeded()
self.tableviewHeight.constant = self.tableview.contentSize.height
self.Scroll.contentSize.height = self.tableviewHeight.constant + 50
self.tableview.setNeedsLayout()
self.tableview.superview?.setNeedsLayout()
self.Scroll.setNeedsLayout()
}
Comments
Post a Comment