iOS 8 introduced a way for tableViews to automatically adjust their cell's height based on their content (via AutoLayout).
// in viewDidLoad: tableView.rowHeight = UITableViewAutomaticDimension tableView.estimatedRowHeight = 44.0
I already got it working with labels, images, etc.
However, I can not figure out a way for the table view cell to grow automatically as soon as a cell's text view changes?
Some more information on the setup: The UITextView inside a cell has horizontal and vertical constraints to the table view cell's contentView. I also disabled scrolling for the text view.
I have also tried to change the height constraint of the cell manually, but the cell would not adopt those changes as well.
If everything is set up properly (Auto Layout constraints) you do not have to calculate anything yourself.
All you have to do is disable UITextView's scrolling enabled property then on textViewDidChange
call tableView.beginUpdates()
and tableView.endUpdates()
.
For a detailed explanation, check out a post I wrote which also includes a working sample project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With