Live resizing of UITableViewCell without using reloadData?

Cashew picture Cashew · Sep 4, 2012 · Viewed 8.6k times · Source

First of all, forgive me if the answer is already out there (I honestly have been working and searching for about two weeks).

And now, the situation:

I have a UITextView as a subview of a UITableViewCell in a UITableView. The UITextView is the first responder (while user is typing).

I have it set up (through delegate protocol methods) so that after each typed character, the cell's rowHeight is recalculated (correctly and in the tableViews delegate protocol for rowHeight). So far everything is fine.

Then, I want that cell to be reloaded (or refreshed, whatever the term may be) without resigning its subview, UITextView, as first responder.

A non-satisfactory solution around the problem:

I am able to use [tableView reloadData] and then [textView becomeFirstResponder] to simulate this (so that user doesn't even notice that the textView was reloaded) and the rowHeight is perfect, but this has been causing me a lot of problems (especially with making sure that the cursor does not jump to the end every time the user types a character and with autocorrect forcefully enforcing its suggestions due to textView resigning).

Is there a way to redraw or resize a UITableViewCell (to dynamically change its rowHeight) without causing any of its subviews to resign as first responder?

Answer

KDaker picture KDaker · Sep 6, 2012

Using tableView's [tableView beginUpdates] and [tableView endUpdates] will solve this issue. See this answer for more information.