Как сделать увеличение высоты UItableview внутри UItableviewcell? - PullRequest
0 голосов
/ 18 апреля 2019

Я просто создаю UITableview (Второй UITableview) внутри UItableviewcell. Мне нужно увеличить UItableviewcell высоту, основываясь на втором номере ячейки UITableview (вторая UITableview's ячейка имела другую высоту).

1-й просмотр таблицы:

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;
   }
}

1-я ячейка таблицы:

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
   }
}

Я ожидаю, что вывод отобразит все ячейки Second UITableview внутри 1-ых UITableview клеток.

но фактический результат - высота ячейки == #no ячейки * 44

1 Ответ

1 голос
/ 18 апреля 2019

В этом методе необходимо указать высоту:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.row == indexOfExtendedCell {
         return 100 // or another height
    }
    return 44
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...