0

I seem to be having some problems settings up my constraints programmatically for a UITableView I am using. My attempt is below, and have tried every combination of using the translatesAutoresizingMaskIntoConstraints possible.

    self.view.translatesAutoresizingMaskIntoConstraints = NO;
    _tableView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-100-[_tableView]-20-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_tableView)]];

I am just trying to add a space to the beginning and bottom of my UITableView on a UIViewController. Could anyone help with this?

The long, long error is below.

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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x75c8500 h=-&- v=-&- UITableView:0x799e400.midY == UIView:0x71a4ec0.midY>",
    "<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-|   (Names: '|':UIView:0x71a4ec0 )>",
    "<NSLayoutConstraint:0x71a5a60 V:|-(100)-[UITableView:0x799e400]   (Names: '|':UIView:0x71a4ec0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-|   (Names: '|':UIView:0x71a4ec0 )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
2013-04-04 20:06:57.648 New eCard[29731:c07] 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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x75c8540 h=-&- v=-&- UITableView:0x799e400.height == UIView:0x71a4ec0.height>",
    "<NSAutoresizingMaskLayoutConstraint:0x75c8500 h=-&- v=-&- UITableView:0x799e400.midY == UIView:0x71a4ec0.midY>",
    "<NSLayoutConstraint:0x71a5a60 V:|-(100)-[UITableView:0x799e400]   (Names: '|':UIView:0x71a4ec0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x71a5a60 V:|-(100)-[UITableView:0x799e400]   (Names: '|':UIView:0x71a4ec0 )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
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) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x75c8540 h=-&- v=-&- UITableView:0x799e400.height == UIView:0x71a4ec0.height>",
    "<NSAutoresizingMaskLayoutConstraint:0x75c8500 h=-&- v=-&- UITableView:0x799e400.midY == UIView:0x71a4ec0.midY>",
    "<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-|   (Names: '|':UIView:0x71a4ec0 )>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x71a5800 V:[UITableView:0x799e400]-(20)-|   (Names: '|':UIView:0x71a4ec0 )>

Break on objc_exception_throw to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.
Alex Muller
  • 1,565
  • 4
  • 23
  • 42
  • Did you create this table view in IB or in code. It shows that you have a mid-y constraint between the table view an the superview. – rdelmar Apr 05 '13 at 02:24
  • Oh I'm really sorry I could have sworn I put that part in there. I used IB. – Alex Muller Apr 05 '13 at 02:38
  • 1
    If you're using IB, why set the constraint in code? When you make the object in IB you get the constraints that Xcode puts in, and they might conflict with the ones you're adding. – rdelmar Apr 05 '13 at 02:43
  • There is a point where I have to be able to change the constraint within my code. – Alex Muller Apr 05 '13 at 04:19
  • Depending on what you need to change, you might be able to make an outlet to the IB set constraints, and just change the constant value. In any case, if you're adding constraints in code you might want to remove the one Xcode added in IB first, so there's no conflict. – rdelmar Apr 05 '13 at 05:36
  • 1
    If you've created the tableview in IB then there shouldn't be any `AutoresizingMaskLayoutContraints` as IB will create normal constraints rather than auto resizing mask ones. Is your xib file set up to use Autolayout? – iain Apr 05 '13 at 14:21

1 Answers1

-2

I found this issue about UICollectionView. I guess that is a good point to start debugging.

UICollectionView Cell + UiLabel with AutoLayout

Some other links with solutions I tried without success : https://blog.safaribooksonline.com/2012/10/27/tip-unsatisfiable-auto-layouts-in-ios-6/ UITableView with autolayout and offset constraints

Community
  • 1
  • 1
MessuKilkain
  • 76
  • 1
  • 1
  • 11