8

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?

Cashew
  • 1,466
  • 2
  • 16
  • 21
  • [this answer](http://stackoverflow.com/a/2063776/442328) should help you. It talks about animation but im pretty sure it does what you are looking for. – KDaker Sep 04 '12 at 16:28
  • Thank you @KDaker , but I actually saw this before and it didn't work (for some strange reason). It seems like it's worth another try. – Cashew Sep 04 '12 at 16:32
  • Other answers or ideas would be greatly appreciated! – Cashew Sep 04 '12 at 16:33
  • anyone? can I at least simply have a textView inside a cell and have the cell resize height on every keyStroke entered in textView? that's all I'm asking for really. – Cashew Sep 05 '12 at 23:56
  • hey, hope you found a solution to your problem. I ran across [this](https://github.com/facebook/three20/) and thought it just MIGHT help you. Look at the TTTextEditor. It is a text editor that expands in size as you type. Im not sure that is going to be helpful in your cell problem but its worth a look. gluck. – KDaker Sep 06 '12 at 17:08
  • Thanks! I discovered that the answer you gave was actually correct (it wasn't working in my app because I had something wrong in there). If you want, you can post the link (beginUpdates one) as an answer and I'll accept it. Thanks again! – Cashew Sep 06 '12 at 19:18

1 Answers1

21

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

Community
  • 1
  • 1
KDaker
  • 5,899
  • 5
  • 31
  • 44