H.Rabiee
H.Rabiee

Reputation: 4837

Autolayout subviews residing in separate xib

In addition to what the title says

  1. Main window has a container view to the left, call this mainContainerView (green background)
  2. In a second .xib I have a NSTableView setup - call it Second.xib (red background)
  3. In the MainViewController.m I add the NSTableView defined in Second.xib and set the constraint as the following

[_mainContainerView addConstraint:[NSLayoutConstraint constraintWithItem:_mainContainerView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:self.second.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];

As you see in the screenshots, the red background does not follow the main container view when I resize the window. Do you know why this is happening?

On startup before resizing After resizing

Edit + Solved

In order to fix this error I had to set constraints for width/height. I also added constraints for top/bottom alignment to superview. After removing translationmask

Upvotes: 0

Views: 86

Answers (1)

Puttin
Puttin

Reputation: 1615

I would prefer:

[_mainContainerView addConstraint:[NSLayoutConstraint constraintWithItem:self.second.view attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:_mainContainerView attribute:NSLayoutAttributeBottom multiplier:1.f constant:0.f]];

Upvotes: 1

Related Questions