Stefan Stefan - 4 months ago 18
Objective-C Question

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];


[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?


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