I'm learning / experimenting with autolayout and UITableViewCell
's. I asked another question a few days ago to which I answered my own question, I'm still using the same constraints / code. For the full code see here: AutoLayout multiline UILabel cutting off some text .
To cut it short inside heightForRowAtIndexPath
I am using an instance of a custom UITableViewCell
to calculate the height the row needs to be. This works perfect in portrait, however when I switch to landscape mode, systemLayoutSizeFittingSize
is returning the same height for the cell as if it was in portrait. I've printed out the frames of the contentView
and the labels and nothing seems to be updating.
The result of this is the constraints are forcing the labels to grow leaving a huge amount of whitespace. The labels display in the correct width, in landscape they are laid out as I would expect, If I hardcode the height of the cell it works perfectly.
It looks like this:
After hardcoding (what I want it to look like):
Even worse I get the same result when running on iPad, even portrait mode, meaning I get the iPhone dimensions. From what I'm seeing it is as though systemLayoutSizeFittingSize
has no concept of orientation or device for that matter.
I've tried faking the frame
the cell should be, tried rotating the cell, calling layoutSubviews
, reloading the tableView
on orientation change and nothing seems to affect it.
Have I missed something basic ?
preferredMaxWidth
in the UILabel subclass, it saved so much code else where – Refreshment