gpt4 book ai didi

iOS:具有动态单元格高度的 UITableViewCell 内的 UITableView

转载 作者:搜寻专家 更新时间:2023-10-31 21:49:36 25 4
gpt4 key购买 nike

我想在 UITableViewCell 中实现 UITableView,并根据内部 UITableView 内容大小实现单元格的动态高度。我该如何实现这个任何建议?我想要这样的布局...

代码工作:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 
let identifier = "OrderHistoryTVCell" let cell: OrderHistoryTVCell! = tableView.dequeueReusableCell(withIdentifier: identifier) as? OrderHistoryTVCell
let tableInnerContentSize = cell.tableInner.contentSize.height
let nn = cell.viewAfterTable.frame.height+tableInnerContentSize
return nn
}

enter image description here

最佳答案

使用以下内容:

@IBOutlet weak var tableView: UITableView! //connect the table view

//do following in viewDidLoad method
tableView.estimatedRowHeight = 100 //Your estimated height
tableView.rowHeight = UITableViewAutomaticDimension

同时从 Storyboard的属性检查器部分设置 UILable 的这两个属性:

  • 行到 0
  • 换行到自动换行

或者您也可以通过代码设置这些属性:

self.lblxyz.numberOfLines = 0
self.lblxyz.lineBreakMode = .byWordWrapping

注意 - 在 TableView 单元格中正确添加约束。

关于iOS:具有动态单元格高度的 UITableViewCell 内的 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42081909/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com