Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Diary App Using Core Data Custom UITableViewCell Customizing Table View Cell Appearance

Trouble filling out the whole body text field

My Body Label text field is only displaying one line of text. I'm not sure if when you input text if it matters if you input a newline into the text. Or if it's supposed to just automatically word wrap your input. I have this in my EntryCell.m

  • (CGFloat)heightForEntry:(DiaryEntry *)entry { const CGFloat topMargin = 35.0f; const CGFloat bottomMargin = 80.0f; const CGFloat minHeight = 106.0f;

    UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]];

    CGRect boundingBox = [entry.body boundingRectWithSize:CGSizeMake(202, CGFLOAT_MAX) options:(NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName: font} context:nil];

    return MAX(minHeight, CGRectGetHeight(boundingBox) + topMargin + bottomMargin); }

1 Answer

UITextField can only handle a single line of text. You'll want to look at using a UITextView instead.

Forrest Wilson
Forrest Wilson
21,862 Points

Where do you change the UITextField to UITextView?

If you're using Interface Builder then you'll need to delete the UITextField, drag in a UITextView, and hook up the outlet to a @property. If you're doing it in code just swap out the class type and initialize the correct object type.

Forrest Wilson
Forrest Wilson
21,862 Points

Oh right, got it! Thanks Marshall!