I have an editable UITextView in every UITableViewCell.
The UITextViews resize fine to pre-loaded text (calculated via heightForRowAtIndexPath) but I'm not sure how to get the smooth-resizing using AutoLayout when adding text dynamically. It just seems to get cut off.
Using AutoLayout, how can I smooth-resize a UITableViewCell and UITextView to fit the text being entered into the UITextView?
Accepted answer is the deprecated one, there is a clean solution for this in iOS 8 sdk
In viewDidLoad, tell the tableView to automatically calculate row heights:
tableView.estimatedRowHeight = 44.0f;
tableView.rowHeight = UITableViewAutomaticDimension;
Implement the textViewDidChange: method of the UITextViewDelegate protocol, and tell the tableView to repaint itself every time the text is edited:
- (void)textViewDidChange:(UITextView *)textView {
[tableView beginUpdates];
[tableView endUpdates];
}
And don’t forget to set the UITextView delegate somewhere, either in Storyboard/IB or in tableView:cellForRowAtIndexPath:
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