I have the following layout for UITableViewCell
:
The layout consists of two subviews:
TopView
(containing aShow
button)BottomView
(which is expanded or collapsed when theShow
button is pressed).
BottomView
consists of 3 subviews. The constraints of these subviews are:
Each of the three subviews contains a
UILabel
that is pinned to theleading
,top
andtrailing
edges with a constant == 8.The
UILabel
is pinned to the bottom of theUIView
using a constraint that is >= 8. This forces theUILabel
to be aligned to the top of theUIView
.The left-most of the three
UIViews
is pinned to the leading edge ofBottomView
.- The right-most of the three
UIViews
is pinned to the trailing edge ofBottomView
- Each of the three
UIViews
is pinned to the top ofBottomView
- Each of the three
UIViews
is pinned to the bottom ofBottomView
- The three views have equal widths and equal heights.
- the bottom of
BottomView
is pinned to the the bottom of theUITableViewCell
's Content View
This gives me my desired layout:
What I'd like to accomplish is the following:
- Initially,
BottomView
should be collapsed. - Clicking on the
Show
button should expand or collapse theBottomView
as appropriate.
I managed to do this by creating a bottomViewHeightConstraint
that is initially uninstalled. Tapping on the show
button activates/deactivates the constraint.
AnotherTableViewCell.m
-(IBAction) show
{
self.bottomViewHeightConstraint.active = !self.bottomViewHeightConstraint.active;
[UIView animateWithDuration:0.3 animations:^{
[self layoutIfNeeded];
[self.delegate cellRequiresUpdates:self];
} completion:^(BOOL finished) {
}];
}
UIViewController.m
-(void) cellRequiresUpdates:(AnotherTableViewCell *)cell
{
[self.tableView beginUpdates];
[self.tableView endUpdates];
}
This worked but produced a lot of warnings for unsatisfiable constraints. I'd like help in understanding which of my constraints are causing the warnings. The unsatisfiable constraints are:
bottomViewHeightConstraint
== 0
(needed because I want to collapse bottom view)
- Equal heights between the left-most and right most
UIView
inUIBottomView
(tried deactivating, but warning didn't go away)
- 8-pixel distance between the bottom of the leftmost UIView and the bottom of
BottomView
(tried deactivating, but warning didn't go away)
- 8-pixel distance between the bottom of the leftmost UIView and the bottom of
BottomView
(tried deactivating, but warning didn't go away)