0

So I created a custom cell with a XIB file and added the constraints: Image. However, the UITextView is not automatically adjusting its height depending on the amount of text inside it.

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 300
}
Rashwan L
  • 38,237
  • 7
  • 103
  • 107

3 Answers3

0

this may help you

 override func viewDidLoad()
        {
            super.viewDidLoad()

           tableView.rowHeight = UITableViewAutomaticDimension
           tableView.estimatedRowHeight = 85
}

and make sure to disable textview scroll and have relation in the top down width hight

this link may help you https://www.raywenderlich.com/129059/self-sizing-table-view-cells

Mohamed Helmy
  • 821
  • 1
  • 9
  • 20
0

You have too many vertical constraints such that it fixes the size of your textView. You should remove one of the top constraints, or just use a stackview as the only child of the content view and give the stack leading trailing, top bottom from the content view (in this case you don't need any other constraints).

Josh Homann
  • 15,933
  • 3
  • 30
  • 33
0

Follow these steps :

  1. Give constraints to ImageView - Leading, Trailing,Top with contentview and Height Constraint(if you want fix height else) give bottom with textview.

  2. Give constraints to TextView - Leading, Trailing, bottom with contentView .

  3. Disable scroll of textView .

  4. Add Following line in ViewDidLoad.

    tableView.rowHeight = UITableViewAutomaticDimension

    tableView.estimatedRowHeight = 44

KKRocks
  • 8,222
  • 1
  • 18
  • 84