0

I'm trying to learn about visual format language and I'm trying to figure out I get a string of breaking Auto Layout constraints.

    /**
 * @Name: setUpContainerViews
 * @Description: This is will set up the different 
 * @Parameters: None
 * @Returns: void
 * @Throws: No Exception
 */

- (void)setUpContainerViews {
    tallContainer = [[UIView alloc] init];
    self.topContainerView = [[UIView alloc] init];
    self.bottomContainerView = [[UIView alloc] init];
    self.leftContainerView = [[UIView alloc] init];
    self.rightContainerView = [[UIView alloc] init];

    // We need to add the subviews here because auto layout needs them to be a part of the view.
    [self.view addSubview: tallContainer];
    [self.view addSubview: self.rightContainerView];

    [tallContainer addSubview: self.topContainerView];
    [tallContainer addSubview: self.leftContainerView];
    [tallContainer addSubview: self.bottomContainerView];

    [self.topContainerView setBackgroundColor: [UIColor blueColor]];
    [self.rightContainerView setBackgroundColor: [UIColor orangeColor]];
    [self.leftContainerView setBackgroundColor: [UIColor greenColor]];
    [self.bottomContainerView setBackgroundColor: [UIColor lightGrayColor]];
}

/**
 * @Name: setUpLayoutConstraints
 * @Description: This will set up the layout constraints
 * @Parameters: none
 * @Returns: void 
 * @Throws: No Exception
 */

- (void)setUpLayoutConstraints {

    // Check if all three properties exist
    NSMutableArray *constraintArray = [NSMutableArray array];

    NSDictionary *views = @{
                                @"tallContainer":tallContainer,
                                @"topContainer":self.topContainerView,
                                @"leftContainer":self.leftContainerView,
                                @"rightContainer":self.rightContainerView,
                                @"bottomContainer":self.bottomContainerView
                           };

    // This is for the self.view
    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"H:|-(0)-[tallContainer]-(0)-[rightContainer(50)]-(0)-|" options:0 metrics:nil views: views]];

    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"V:|-(0)-[tallContainer]-(0)-|" options:0 metrics:nil views: views]];
    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"V:|-(0)-[rightContainer]-(0)-|" options:0 metrics:nil views: views]];

    // This is for the tall container
    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"V:|-(0)-[topContainer(75)]-(0)-[leftContainer]-(0)-[bottomContainer(75)]-(0)-|" options:0 metrics:nil views: views]];

    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"H:|-(0)-[topContainer]-(0)-|" options:0 metrics:nil views: views]];
    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"H:|-(0)-[leftContainer]-(0)-|" options:0 metrics:nil views: views]];
    [constraintArray addObjectsFromArray: [NSLayoutConstraint constraintsWithVisualFormat: @"H:|-(0)-[bottomContainer]-(0)-|" options:0 metrics:nil views: views]];

    // This will add the constraints
    [self.view addConstraints: [constraintArray copy]];
}

And these are first broken constraints which need to more...

       2015-05-16 11:08:34.222 HighSchoolUMS[4776:1420732] 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:0x7fe898e11760 V:|-(0)-[UIView:0x7fe898e0f210]   (Names: '|':UIView:0x7fe898e0f100 )>",
        "<NSLayoutConstraint:0x7fe898e117e0 V:[UIView:0x7fe898e0f210(75)]>",
        "<NSAutoresizingMaskLayoutConstraint:0x7fe898d2bb80 h=--& v=--& UIView:0x7fe898e0f210.midY ==>"
    )

    Will attempt to recover by breaking constraint 
    <NSLayoutConstraint:0x7fe898e11760 V:|-(0)-[UIView:0x7fe898e0f210]   (Names: '|':UIView:0x7fe898e0f100 )>

    Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
    The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

I don't know why they are breaking it seems like a simple enough thing am I missing something here? (Obviously I am) This app is in landscape orientation is that helps at all.

Michael Choi
  • 285
  • 1
  • 3
  • 15
  • 1
    possible duplicate of [Unable to simultaneously satisfy constraints, will attempt to recover by breaking constraint](http://stackoverflow.com/questions/11664115/unable-to-simultaneously-satisfy-constraints-will-attempt-to-recover-by-breakin) – vacawama May 16 '15 at 18:46
  • 1
    Look at the link. The answer with 66 up votes is your answer. Set that flag to `NO` for each of your programmatically created sub views. – vacawama May 16 '15 at 18:51

0 Answers0