I have my own cross platform widget layout system that I use for most things so I have never had to use layout constraints before, so this is my first dive into it. My code is in Objective-C not Swift and all of the examples I find are sadly in Swift. By default my UITableView will only show an Icon and Text. However it has extra "column" icons and text that would be in individual columns on MacOS or other desktop platforms. I have a toggle that will allow this additional information to be displayed in an either horizontal or vertical UIStackView. So if toggled I want to add the UIStackView to the UITableViewCell placed under the textLabel expanding the UITableViewCell by whatever size the UIStackView requires. My thought was I could do this by adding 3 constraints connecting the UIStackView, contentView and textLabel together. This didn't produce the expected result. The first two constraints correctly position the UIStackView below the textLabel but did not expand the UITableViewCell. Adding the third (bottom) constraint to expand the cell, instead clips the UIStackView out of the cell entirely. Can someone point out what I am doing wrong?
/* If we don't have a stack, create one */
NSLayoutConstraint *constraint;
stack = [[[UIStackView alloc] init] retain];
[stack setTranslatesAutoresizingMaskIntoConstraints:NO];
[stack setSpacing:5.0];
[[self contentView] addSubview:stack];
/* Leading */
constraint = [NSLayoutConstraint constraintWithItem:stack attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual toItem:[self contentView]
attribute:NSLayoutAttributeLeft multiplier: 1.0 constant:0.0];
[[self contentView] addConstraint:constraint];
/* Top */
constraint = [NSLayoutConstraint constraintWithItem:stack attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual toItem:[self textLabel]
attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
[[self contentView] addConstraint:constraint];
/* Bottom */
constraint = [NSLayoutConstraint constraintWithItem:[self contentView] attribute:NSLayoutAttributeBottom
relatedBy:NSLayoutRelationEqual toItem:stack
attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0];
[[self contentView] addConstraint:constraint];