Ios 如何在UItableviewcell内增加UItableview高度?
我只是在Ios 如何在UItableviewcell内增加UItableview高度?,ios,swift,uitableview,Ios,Swift,Uitableview,我只是在UItableviewcell内创建UITableview(第二个UITableview)。我需要根据第二个UITableview单元格的数量增加UITableview单元格的高度(第二个UITableview的单元格的高度不同) 1st tableview: extension ViewController:UITableViewDelegate, UITableViewDataSource{ // no of row #1 func tableView(_ tableVi
UItableviewcell
内创建UITableview
(第二个UITableview
)。我需要根据第二个UITableview单元格的数量增加UITableview单元格的高度(第二个UITableview的
单元格的高度不同)
1st tableview:
extension ViewController:UITableViewDelegate, UITableViewDataSource{
// no of row #1
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "OrderTimelineCell", for: indexPath) as! OrderTimelineCell
return cell;
}
}
override func awakeFromNib() {
tableView.layoutIfNeeded()
tableView.heightAnchor.constraint(equalToConstant: tableView.contentSize.height).isActive = true //always return 44*#cells
}
extension OrderTimelineCell:UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TimelineTableViewCell", for: indexPath) as! TimelineTableViewCell
cell.label.text = array[indexpath.row] // text height different
return cell
}
}
第一个tableview单元格:
extension ViewController:UITableViewDelegate, UITableViewDataSource{
// no of row #1
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "OrderTimelineCell", for: indexPath) as! OrderTimelineCell
return cell;
}
}
override func awakeFromNib() {
tableView.layoutIfNeeded()
tableView.heightAnchor.constraint(equalToConstant: tableView.contentSize.height).isActive = true //always return 44*#cells
}
extension OrderTimelineCell:UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TimelineTableViewCell", for: indexPath) as! TimelineTableViewCell
cell.label.text = array[indexpath.row] // text height different
return cell
}
}
我希望输出显示第二个UITableview
单元格中第一个UITableview
单元格的所有单元格
但实际输出为单元格高度=#单元格*44的编号您需要在此方法中指定高度:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == indexOfExtendedCell {
return 100 // or another height
}
return 44
}
不希望静态指定(返回100)。因为,文本动态地进入单元格,您必须通过此方法指定它。单元子视图的每次更改都需要计算高度并在此处更新高度。这并不可怕。