У меня динамическое табличное представление внутри статического табличного представления.Я не могу изменить высоту ячейки в зависимости от содержимого ячейки.Я пробовал различные методы, такие как
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (ProfileData.profileViewType == .favourite) {
if let cell = tableView.dequeueReusableCell(withIdentifier: "profileCell", for: indexPath) as? ProfileCell { // gives EXC_BAD_ACCESS in SimpleCheckbox library
cell.favouritesTitleLabel.numberOfLines = 0
cell.favouritesTitleLabel.sizeToFit()
print(cell.favouritesTitleLabel.text)
let height = cell.favouritesTitleLabel.text!.height(withConstrainedWidth: cell.frame.width - 64, font: UIFont(name: "Roboto", size: 17.0)!)
print(height + 16)
return height + 16
}
}
return UITableView.automaticDimension
}
Я пытался установить UITableView.automaticDiemension
, но он не настраивается в текстовом режиме.Это становится больше.Если я попытаюсь tableView.dequeueReusableCell(withIdentifier: "profileCell") as! ProfileCell
я получаю только содержимое двух ячеек, а остальные не получают текстовое значение.
Текущий снимок экрана пользовательского интерфейса: снимок экрана пользовательского интерфейса
Я установил следующую конфигурацию табличного представления в viewDidLoad()
:
profileTableView = ProfileSectionTableView()
profileTableView.profileDelegate = self
profileSectionTableView.delegate = profileTableView
profileSectionTableView.dataSource = profileTableView
profileSectionTableView.rowHeight = UITableView.automaticDimension
profileSectionTableView.estimatedRowHeight = 44