I have a dynamic tableview inside a static table table view. I am not able to change the cell height according to the cell content. I have tried various methods like

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

I have tried setting UITableView.automaticDiemension, but it is not adjusting to the text view. It is getting larger. If I try tableView.dequeueReusableCell(withIdentifier: "profileCell") as! ProfileCell I am getting only the contents of two cells and rest are not getting the text value.

Related posts

Recent Viewed