Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在UItableviewcell内增加UItableview高度?_Ios_Swift_Uitableview - Fatal编程技术网

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)。因为,文本动态地进入单元格,您必须通过此方法指定它。单元子视图的每次更改都需要计算高度并在此处更新高度。这并不可怕。