i want to make dynamic height collectionView like below picture, i use collectionView in tableView.
so i set collectionView's data in tableViewDataSource.
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "MyTableViewCell") as? MyTableViewCell else {
return UITableViewCell()
}
cell.setLabelArray(label[indexPath.row])
cell.titleLabel.text = titleArray[indexPath.row]
return cell
}
and then in tableViewCell, i adjust collectionView's height.
class MyTableViewCell: UITableViewCell {
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var myCollectionView: MyCollectionView!
@IBOutlet weak var collectionViewHeight: NSLayoutConstraint!
var labelArray: [String]? {
didSet {
myCollectionView.reloadData()
let height = self.myCollectionView.collectionViewLayout.collectionViewContentSize.height
self.collectionViewHeight.constant = height
}
}
...
but layout's contentSize is always different when i use flowLayout (like below last picture)
how can i get correct contentSize?? .......