0

I'm having issues with an Autolayout custom TableViewCell in iOS 7. The cell appears to display correctly, but I get a good deal of debugging console output, such as the following:

Unable to simultaneously satisfy constraints.
Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property
translatesAutoresizingMaskIntoConstraints) 
(
"<NSLayoutConstraint:0x7f9c1a4b8500 V:[UILabel:0x7f9c1a4b72d0]-(0)-[UILabel:0x7f9c1a4b7680]>",
"<NSLayoutConstraint:0x7f9c1a4b8550 V:[UILabel:0x7f9c1a4b7680]-(0)-[UILabel:0x7f9c1a488910]>",
"<NSLayoutConstraint:0x7f9c1a4b85c0 V:[UILabel:0x7f9c1a488910]-(NSSpace(20))-|   (Names: '|':UITableViewCellContentView:0x7f9c1a4b66d0 )>",
"<NSLayoutConstraint:0x7f9c1a4b87f0 V:|-(NSSpace(20))-[UILabel:0x7f9c1a4b6f00]   (Names: '|':UITableViewCellContentView:0x7f9c1a4b66d0 )>",
"<NSLayoutConstraint:0x7f9c1a4b8840 V:[UILabel:0x7f9c1a4b6f00]-(NSSpace(8))-[UILabel:0x7f9c1a4b72d0]>",
"<NSAutoresizingMaskLayoutConstraint:0x7f9c1a4a70e0 h=--& v=--& V:[UITableViewCellContentView:0x7f9c1a4b66d0(44)]>"
)

I only get this output in iOS 7, and I see it on all of my custom table view cells, across multiple view controllers. I have followed all of the steps in this post:(Using Auto Layout in UITableView for dynamic cell layouts & variable row heights). I have tried adjusting the AutoresizingMask of the content view in these cells, but it does not stop these errors from appearing. I would greatly appreciate some advice on fixing these errors. Thanks!

Community
  • 1
  • 1
  • There is something really funky going on with auto layout in a `UITableViewCell` in iOS7. I've asked about it here: http://stackoverflow.com/questions/28696264/ambiguous-layout-warnings-for-uilabels-in-uitableviewcell, but have not yet found a solution. – koen Mar 12 '15 at 18:38
  • Yeah, I've been checking out every post I can find about this, I think I came across your post earlier. If it is just some bug with iOS 7, will the console output have any effect on app store approval? Obviously its less than ideal, but the UI looks and behaves perfectly fine. – Alex Lipsett Mar 12 '15 at 18:48
  • FYI, I finally figured out what was my problem, I had to add `setContentHuggingPriority` with a `UILayoutPriorityFittingSizeLevel` priority for the horizontal axis. – koen Mar 15 '15 at 14:07

2 Answers2

1

The last one, "NSAutoresizingMaskLayoutConstraint:0x7f9c1a4a70e0 h=--& v=--& V:[UITableViewCellContentView:0x7f9c1a4b66d0(44)]"

could indicate that in the tableviewcell the translatesAutoresizingMaskIntoConstraints property is set to YES. If this is the case try to set it to NO to avoid conflicts between your constraints and the automatic ones.

mikemm13
  • 81
  • 4
  • This fixed the issue, but now the cell's content does not take up the full horizontal space of the cell. – Alex Lipsett Mar 13 '15 at 17:26
  • I was able to fix this issue by constraining the width of the cells content view to the width of the cell. This works for ios7 but breaks layouts in ios8 – Alex Lipsett Mar 13 '15 at 19:25
0

This means that you have constraints that conflict, and it is picking to satisfy one since they cannot all be satisfied.

Usually this means that you either have: 1)Constraints you know will not be satisfied simultaneously such as a minimum size or offset combined with a percentage or ratio. In this case all you need to do is reduce the priority of the one you want to break first.

Or, 2) duplicate constraints worded differently(center vertically, but also trailing space, etc) this one is harder for me to remotely diagnose, so posting the constraint would be important.

If the particular constraints are not that important to you (AKA you didn't spend that long adding them) then removing them all, adding suggested, and working from there is a very valid starting point.

Tim
  • 2,878
  • 1
  • 14
  • 19
  • If the constraints were conflicting, wouldn't I also be getting errors in iOS8? Also, the layout looks totally correct as far as I can tell, I don't see any UI elements out of position or missized as I normally do with conflicts. – Alex Lipsett Mar 12 '15 at 18:35
  • Depends on the device, as they may only conflict at certain resolutions (AKA did you try the same device/resolution on the two OS versions.) Also, depending on which constraints were broken, lots of times the UI looks decent because they ignored the constraints that are least usable. For example, Center Vertically but Trailing space, if the center vertically is obeyed you likely wouldn't notice because it would be centered. – Tim Mar 12 '15 at 18:40
  • Yeah, if it run the code on an iPhone 4S simulator running 8.2 I don't get any issues, but if I run it on an iPhone 4s simulator running 7.1 I'll get it. Same deal with the 5s. I'll double check to make sure there are no conflicts though. Most of the console output makes sense to me, with the exception of this "[UITableViewCellContentView:0x7f9c1a4b66d0(44)." From my understanding that means that the ContentView of the cell is trying to be vertically constained to a height of 44, but I'm using the correct heightForTableViewCell code as per the link. I don't normally see that during conflicts. – Alex Lipsett Mar 12 '15 at 18:45
  • BTW you were also correct to a degree, on the smaller screen size on iOS 7 the font size of a label was being shrunk slightly. Didn't notice it until just recently. – Alex Lipsett Mar 13 '15 at 17:50