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 Custom UITableViewCell with Dynamic Height

Need a Little alternative iOS6.1

Hi, Somebody might be able to give me a dig out here. I'm on the Dynamic Height stage of building the Diary App and my version of Xcode (4.6) doesn't support the framework method boundingRectWihSize:

If any one knows a good alternative, I would much appreciate it. I managed to get this far with some adjustments but now I am stumped.

My disadvantage is that my stallwart Mac Pro 1.1 will not die and keeps going strong but has stalled my progress to newer Xcodes.

4 Answers

Stone Preston
Stone Preston
42,016 Points

you may be able to use sizeWithFont and constrainedToSize methods to find the height of the container that the string will fit in with a given width:

float height = [string sizeWithFont:[UIFont systemFontOfSize:kFontSize] constrainedToSize:CGSizeMake(width, 999999.0f) lineBreakMode:NSLineBreakByWordWrapping].height + verticalPadding;

that might be of some use to you

Cheers, will give it a go.

Hi Stone tried your solution as so :

'''+ (CGFloat)heightForEntry:(SVDiaryEntry *)entry { const CGFloat topMargin = 35.0f; const CGFloat bottonMargin = 39.0f; const CGFloat minHeight = 85.0f;

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

float height = [string sizeWithFont:[UIFont systemFontOfSize:kFontSize] constrainedToSize:CGSizeMake(width, 999999.0f) lineBreakMode:NSLineBreakByWordWrapping].height + verticalPadding;

return height;

}'''

Not sure if this is what you intended, but in context to what I had already I am not sure how it fits in. The compiler is complaining about string and kFontSize and I am not sure where verticalPadding fits in.

Stone Preston
Stone Preston
42,016 Points

Those are variables. You will have to replace those with your own values. Use whatever font size is being used in the table view. Your are probably going to have to play around with the value of the vertical padding and see what works.

Ok, cheers, got this working after a fashion. Text isn't wrapping in the body section. I is being clipped, but this is enough to keep things moving. Have the no-image and smiley working. : )