Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change UITableView row height without dismissing keyboard

I have a TextView inside a UITableViewCell. The text inside the TextView can be edited right there in place.

The TextView grows and shrinks vertically depending on the number of lines the text contains. So far I haven't found a possibility to also let the row containing the TextView grow and shrink dynamically.

[tableView reloadData];

or

[tableView reloadRowsAtIndexPaths: withRowAnimation:];

don't work, because they dismiss the keyboard on every change.

Is there a way to change height of an individual row in a UITableView without dismissing keyboard?

like image 842
Stefan Avatar asked Mar 17 '11 19:03

Stefan


1 Answers

Yes, you can have the row heights adjust as you type. It's not documented, and it defies reason, but all you need to do is set the new value in tableView.rowHeight (or have heightForRowAtIndexPath:ready to compute the new heights), then do this:

[tableView beginUpdates]; // updates the row heights ...
[tableView endUpdates]; // ... nothing needed in between
like image 82
Jeff Avatar answered Oct 20 '22 21:10

Jeff