Skip to content

Instantly share code, notes, and snippets.

@maxkramer
Created October 14, 2014 18:46
Show Gist options
  • Save maxkramer/fc028c78bc2a92cab8eb to your computer and use it in GitHub Desktop.
Save maxkramer/fc028c78bc2a92cab8eb to your computer and use it in GitHub Desktop.
NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.tableView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0];
NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.tableView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1.0 constant:-CGRectGetHeight(self.searchBar.frame)];
NSLayoutConstraint *leftConstraint = [NSLayoutConstraint constraintWithItem:self.tableView attribute:NSLayoutAttributeLeft relatedBy:0 toItem:self.view attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
NSLayoutConstraint *bottomConstraint = [NSLayoutConstraint constraintWithItem:self.tableView attribute:NSLayoutAttributeBottom relatedBy:0 toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[self.tableView setTranslatesAutoresizingMaskIntoConstraints:YES];
[self.view addConstraint:widthConstraint];
[self.view addConstraint:heightConstraint];
[self.view addConstraint:leftConstraint];
[self.view addConstraint:bottomConstraint];
@algal
Copy link

algal commented Oct 14, 2014

I find erasing ~/Library/Developer/Xcode/DerivedData/projectname-blahblah/ often works wonders.

@maxkramer
Copy link
Author

I've made the suggested changes, which didn't affect the layout either. I have however tracked back the IB generated constraint to being a result of the Y value of the table view not being 0 initially. The fix for this would of course be setting the Y value to 0, but this didn't get rid of the constraint.

Ha, I had a derived data exterminator from Alcatraz, but I haven't got around to reinstalling it yet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment