Skip to content

Commit

Permalink
Merge pull request smileyborg#8 from madewulf/master
Browse files Browse the repository at this point in the history
Call [super updateConstraints] as the final step in updateConstraints implementation
  • Loading branch information
smileyborg committed Sep 22, 2014
2 parents 1b52a65 + 8391d51 commit c158ba0
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions TableViewCellWithAutoLayout/TableViewController/RJTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,39 +68,37 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus

- (void)updateConstraints
{
[super updateConstraints];

if (self.didSetupConstraints) {
return;
if (!self.didSetupConstraints) {
// Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception.
// As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below.
// See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188
// self.contentView.bounds = CGRectMake(0.0f, 0.0f, 99999.0f, 99999.0f);

[UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
[self.titleLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
}];
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kLabelVerticalInsets];
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];

// This is the constraint that connects the title and body labels. It is a "greater than or equal" inequality so that if the row height is
// slightly larger than what is actually required to fit the cell's subviews, the extra space will go here. (This is the case on iOS 7
// where the cell separator is only 0.5 points tall, but in the tableView:heightForRowAtIndexPath: method of the view controller, we add
// a full 1.0 point in extra height to account for it, which results in 0.5 points extra space in the cell.)
// See https://github.com/smileyborg/TableViewCellWithAutoLayout/issues/3 for more info.
[self.bodyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.titleLabel withOffset:kLabelVerticalInsets relation:NSLayoutRelationGreaterThanOrEqual];

[UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
[self.bodyLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
}];
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets];

self.didSetupConstraints = YES;
}

// Note: if the constraints you add below require a larger cell size than the current size (which is likely to be the default size {320, 44}), you'll get an exception.
// As a fix, you can temporarily increase the size of the cell's contentView so that this does not occur using code similar to the line below.
// See here for further discussion: https://github.com/Alex311/TableCellWithAutoLayout/commit/bde387b27e33605eeac3465475d2f2ff9775f163#commitcomment-4633188
// self.contentView.bounds = CGRectMake(0.0f, 0.0f, 99999.0f, 99999.0f);

[UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
[self.titleLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
}];
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTop withInset:kLabelVerticalInsets];
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
[self.titleLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];

// This is the constraint that connects the title and body labels. It is a "greater than or equal" inequality so that if the row height is
// slightly larger than what is actually required to fit the cell's subviews, the extra space will go here. (This is the case on iOS 7
// where the cell separator is only 0.5 points tall, but in the tableView:heightForRowAtIndexPath: method of the view controller, we add
// a full 1.0 point in extra height to account for it, which results in 0.5 points extra space in the cell.)
// See https://github.com/smileyborg/TableViewCellWithAutoLayout/issues/3 for more info.
[self.bodyLabel autoPinEdge:ALEdgeTop toEdge:ALEdgeBottom ofView:self.titleLabel withOffset:kLabelVerticalInsets relation:NSLayoutRelationGreaterThanOrEqual];

[UIView autoSetPriority:UILayoutPriorityRequired forConstraints:^{
[self.bodyLabel autoSetContentCompressionResistancePriorityForAxis:ALAxisVertical];
}];
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeLeading withInset:kLabelHorizontalInsets];
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeTrailing withInset:kLabelHorizontalInsets];
[self.bodyLabel autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:kLabelVerticalInsets];

self.didSetupConstraints = YES;
[super updateConstraints];
}

- (void)layoutSubviews
Expand Down

0 comments on commit c158ba0

Please sign in to comment.