I am using the iOS Reminders App on my iPhone, and I was noticing that inside the tableview it allows you to enter text that can wrap around to a new line and continue entering text for a reminder. I notice that the height of the cell changes to accommodate the size of the reminder text supplied. My question is I know this could be done with a UILabel, but you can't edit and enter text in a UILabel can you? So it must be a UITextField, but I thought a UITextField didn't allow the words to wrap to a new line? I thought it just continued to shrink itself down on one line? So what am I missing here?
Asked
Active
Viewed 1,107 times
2 Answers
1
It most likely uses a UITextView
which does allow multiple text lines. You can then change the height of the UITableViewCell
when the text wraps to the next line by looking at the delegate methods of UITextView
.

James Paolantonio
- 2,194
- 1
- 15
- 32
-
I didn't see anything in the docs, that suggested a UITextField can have multiple lines of text, but thanks I guess I just missed it? – I00I Aug 30 '12 at 12:09
0
Have you tried UITextView, it does the auto wrapping for you, but to auto resize the table cell height, might have to use the textViewDelegate didReplaceString method.
// goes inside the UITextView didReplaceString method
// assumes expectedTextSize is a CGSize struct (like this CGSize expectedTextSize)
expectedTextSize = [myTextView.text sizeWithFont:[UIFont fontWithName:"Arial" size:12] constrainedToSize:CGSizeMake(200, 999999) lineBreakMode:UILineBreakModeWordWrap];
// then in your tableView:heightForRow: table view delegate method
return expectedTextSize.height;

Zhang
- 11,549
- 7
- 57
- 87
-
I think you might be correct. Thank you very much. This has been tested here. http://stackoverflow.com/a/1345724/223480 – I00I Aug 30 '12 at 12:11