1

My problem is similar to this and that SO question. Now the content view has no height problem anymore because I added an auto resizing mask (flexible height/width) to the content view in updateConstraints of my custom table view cell for iOS 7.

But the height of the cell still has the same problem. It gets a height of 44 points from the auto resizing mask.

Unable to simultaneously satisfy constraints  
// ...
"<NSAutoresizingMaskLayoutConstraint:0x7a4f61f0 h=-&- v=--&
V:[TestCellAuto_CustomCell:0x7a43bb10(44)]>"

The layout is completely destroyed and in the output I get the above error. On iOS 8.1 everything is working fine. Only iOS 7 makes this problems.

How can I tell iOS that it should calculate the correct cell height?

Seems that you have to set rowHeight or implement heightForRowAtIndexPath as described in Using Auto Layout in UITableView for dynamic cell layouts & variable row heights.

The height of my cells is always the same, but I don't know why auto layout can't calculate the row height correctly on iOS 7. On iOS 8 the height of the row is wrong after rotation and the layout is messed up. Only if I call reloadData in willRotateToInterfaceOrientation:duration: solves the problem. But for iOS 7 I still have to set the height. Not an ideal solution.

To sum up, this is what I've to do now:

iOS 7:

  1. self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; before adding constraints and
  2. define a fixed rowHeight

The first is for the contentView and the second for the UITableViewCell.

iOS 8:

  • I can either set a fixed rowHeight or
  • use reloadData in willRotateToInterfaceOrientation:duration:

What is wrong with auto layout? Am I doing something wrong? Are you always setting a fixed height?

Community
  • 1
  • 1
testing
  • 19,681
  • 50
  • 236
  • 417
  • 1
    iOS 7 did not allow the cell height to be calculated automatically from the constraints. iOS 8 does allow this. If you need to support iOS 7 you will have to perform the calculation from the constraints / implicit sizes yourself. – Robotic Cat Nov 11 '14 at 15:41
  • Thanks for your reply. Why does the sizing information gets lost when I rotate the device on iOS 8? It seems that I'm missing something. For iOS 8 I don't need to calculate - it's done automatically as you said (except the rotation problem). How does your calculation does look like? The same like in the linked post *Using Auto Layout in UITableView for dynamic cell layouts & variable row heights*? – testing Nov 11 '14 at 18:49
  • I have no idea why the sizing information is not working when you rotate on iOS 8. It should just work so I think it must be something in your constraints. For iOS 7 I always went with a fixed row height but basically if you follow that linked post it will work. So I'm not sure what you're missing. I suggest you post a more specific question about the iOS 8 rotation problem with example code & pictures of your constraints. – Robotic Cat Nov 11 '14 at 20:01
  • 1
    http://stackoverflow.com/questions/26881764/on-rotation-cell-height-gets-lost-on-ios-8-when-using-auto-layout – testing Nov 12 '14 at 07:48

0 Answers0