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 - Programmatically

First of all - Great course!

I'm not the biggest fan of storyboards, so when following along the course I did it programmatically. There is only one thing I'm having a slight problem with:

When implementing the function the gives us dynamic height for our labels. I can get this part to work. I.e if the body-text is to long it won't resize properly.

I'll include the project, so you can have a look.

https://www.dropbox.com/s/bdz8ri649ut0eoi/Diary.zip

CC: Ash Furrow and Amit Bijlani

3 Answers

Ash Furrow
STAFF
Ash Furrow
Treehouse Guest Teacher

Looks like the culprit is a mixture of two things. First, the line break mode is incorrect:

    [_bodyLabel setLineBreakMode:NSLineBreakByTruncatingTail];

It should be NSLineBreakByWordWrapping.

Next, your autoresizing mask should be:

    [_bodyLabel setAutoresizingMask:UIViewAutoresizingFlexibleHeight];

Instead of setting it multiple times (only the last line has any effect). Those two changes should point you in the right direction.

Thanks for your help, but in your project in the storyboard you set lineBreakMode to NSLineBreakByTruncatingTail and setAutoresizingMask to more than just flexible height. Why does this not work in code?

Ash Furrow
Ash Furrow
Treehouse Guest Teacher

Ah, you're right. Setting the autoresizing mask correctly is sufficient.

but how would I go about setting that in code if only the last line have effect? Also, my location label is in the middle my body-label now.