Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the height of a UITableViewCell be changed without reloading the table view?

I'm trying to resize a UITableViewCell without reloading the table view.

My UITableViewCell contains a UITextView so users can input list items that may be several lines (about four max) in length. Right now, I'm resizing the text view each time the user presses the return key, but I'd like to change the height of the table view cell as well.

The main problem I'm running into is that reloading the table view's data makes the text view lose focus. Is there any way to change the height of the UITableViewCell without reloading the table view, letting the user continue to input text in the text view?

like image 778
Yanik Magnan Avatar asked Mar 01 '11 20:03

Yanik Magnan


1 Answers

To resize a table view row, try sending:

[tableView beginUpdates];
[tableView endUpdates];

These messages one immediately after the other should do the trick provided you have the correct height returned for that cell in the tableView:heightForRowAtIndexPath: method. The row should animate. You should be able to return the height of your cell using its bounds or just from knowing what you've set the cell height as.

Obviously "tableView" is the name of your table view.

like image 199
Robotic Cat Avatar answered Sep 22 '22 15:09

Robotic Cat