Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
695 views
in Technique[技术] by (71.8m points)

objective c - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...