Use*_*ser 3 uitableview ios swift3
在这里,我有一个如下所示的设计,其中我设计了除了最后一个单元格之外的所有单元格,在该单元格中我有一个集合视图,我需要加载数据,这是分页所以如何给这个单元格的高度,当集合视图高度根据我的数组计数动态增加.任何人都可以帮助我动态地给出身高或任何建议/想法来实现这个?
鉴于以下结构:
的TableView
表视图单元格
表视图单元格
TableViewCell
的CollectionView
CollectionViewCell
CollectionViewCell
CollectionViewCell
[...可变数量的细胞或不同的细胞大小]
小智 9
将表视图行高设置为自动维
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44
为collectionView
内部高度创建IBOutlet tableViewCell
.集leading
,trailing
,top
,bottom
约束的collectionView
内部tableViewCell
.
为collectionView
under 创建outlet tableViewCell
(如objCollectionView)并在cellForRowAt indexPath
方法内添加以下代码
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) as! tableCell
cell.frame = tableView.bounds
cell.layoutIfNeeded()
cell.objCollectionView.reloadData()
cell.objCollectionViewHeightConstraint.constant = cell.objCollectionView.contentSize.height
return cell;
}
Run Code Online (Sandbox Code Playgroud)这将自动调整高度tableViewCell
取决于它的内容.
归档时间: |
|
查看次数: |
2095 次 |
最近记录: |