Swift / how to use UITextView with dynamic height INSIDE UITableViewCell with dynamic height

Get programmatically height of textview...

let textView = UITextView()//your Text view
let sizeThatShouldFitTheContent = textView.sizeThatFits(textView.frame.size)
let height = sizeThatShouldFitTheContent.height

OR try this demo...

Self-sizing UITextView in a UITableView

https://www.damienpontifex.com/posts/self-sizing-uitableviewcell-with-uitextview-in-ios8/


If you are using UITableViewAutomaticDimension then you must set serial constraints from top to bottom. Without autolayout or proper constraints UITableViewAutomaticDimension won't work. So you can manage this thing something like: set top,bottom,leading,trailing and fixed height constraints to your textview. then take outlet of fixed height constraint and increase it's constant instead changing or setting frame of textview and everythng will work I think!


Step 1, Disable Scrolling of TextView
Step 2, Add Top, Left, Right and bottom constraint
Step 3, Set Delegate to textView
Step 4, Implement below UITextViewDelegate Method

- (void)textViewDidChange:(UITextView *)textView {
[UIView setAnimationsEnabled:false];
[textView sizeToFit];
[self.tableView beginUpdates];
[self.tableView endUpdates];
[UIView setAnimationsEnabled:true];}