So i subclassed UITableViewCell and have an appropriate xib file for it.
To keep it simple lets just say i have 3 UILabel
s side by side.
All of them have a spacing of 8 to each other and are resized to fit its content except the first one, which takes the remaining space in the cell.
The first label (Label1) has trailing space constraints to both other labels and the superview. Those constraints have their Installed
property not checked and are connected to my subclass via IBOutlet
s.
Visually it could look like this:
[Label1] - Spacing - [Label2] - Spacing - [Label3]
Depending on the data displayed, the right 2 UILabel
s can be hidden. If the first one is hidden it should look like this:
[Label1] - Spacing - [Label3]
Hiding the label is done in tableView:cellForRowAtIndexPath:
in which i also call a method to set the appropriate constraint from the xib-file which can be accessed via an IBOutlet
. This is working perfectly. But when rotating the device, the constraints are reloaded from the xib-file in which no constraint is Installed
, but updateConstraints
is not called again on my UITableViewCell
-subclass, messing everything up.
One way to fix it would be by, instead of calling the method, which sets the appropriate constraint active, in tableView:cellForRowAtIndexPath:
i could call it in layoutSubviews
in my UITableViewCell
-subclass. But i think you shouldn't update constraints in layoutSubviews
.