Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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. : )