2

I'm using AutoLayout for iOS 8 in Xcode 6, and the last step I need on this custom Table View Cell is to add a "Bottom Space to Container Margin" constraint so my Table View Cell increases its size based on the size of the text in the Label Description...

However, whenever I add the Bottom Space to Container Margin constraint, I get a bunch of warnings, yet if I do all the changes needed, it ends up clipping labels (all of Headline Label, bottom of Date Label), I'm assuming because its setting some at higher priority. And gives me this warning in the console that I'm not sure if it relates to this or something else: "Probably at least one of the constraints in the following list is one you don't want."

And I can't really run the project without cleaning up those AutoLayout warnings/errors, so was wondering if you had any ideas on what I could do or am missing?

enter image description here

Thanks!

UPDATE: The problem here was related to what the accepted answer had said, but I wanted to make the Q&A a bit clearer now that I have it figured out for anyone else that comes across this.

The problem was that there were fixed constraints for the height of the cell. These can either be set in storyboard or in the code (i.e. heightForRowAtIndexPath), so make sure to check BOTH OF THESE PLACES. Once that has been removed, make sure to set UITableViewAutomaticDimension.

What also helps is to use the Pin menu. Sometimes the labels can run off screen because it doesn't know where the constraints of the cell are based on the device size. So your label can run offscreen if the label is based off of a landscape layout but the device is an iPhone 5 and is in Portrait for example. This is the Pin menu:

enter image description here

Also, these things can be debugged in Storyboard Assistant Editor: Device Preview, where you are able to see the layout and layers of what is onscreen to see if maybe you have labels overlapping or going offscreen based on the device it is running on. If you want to check multiple device sized, just hit the plus icon in the lower left hand corner of this picture.

enter image description here

Hope I was able to clear this up so it made more sense, and provide some help while doing so!

Realinstomp
  • 532
  • 2
  • 13
  • 30

1 Answers1

2

You didn't show us all your constraints, but it sounds like you have a fixed height constraint for the cell.

Since you're letting the label description height grow, Auto Layout thinks the headline and/or date will have to shrink (to maintain the cell's fixed height). That's why you're getting (misleading) errors about not knowing which of the two labels to prioritize not compressing.

Remove any fixed height constraint, and make sure your cell height is set to UITableViewAutomaticDimension. That should clear up the Auto Layout warnings and errors.

smileyborg has an excellent Auto Layout table view cell project that will walk you through the iOS 8 self-sizing cell feature.

Community
  • 1
  • 1