I have a UITableView
that has multiple sections, with custom UITableViewCell
subclasses populating the table. Within these UITableViewCell
subclasses, I am implementing layoutSubviews
to customize the position of labels, etc.
All of the cell's subviews are adjusting as they should, except the first batch of visible cells upon the view loading. They are identical to how they are laid out in storyboard, which is not what I want. For example:
http://i.stack.imgur.com/L5GJh.png
Note: The green and orange borders are a visual aid to see if the labels are resizing.
Upon scrolling, all of the new cells that appear have their subviews the way that I programmed them to be in layoutSubviews
. As far as the first batch of visible cells, I can scroll them offscreen and then back on, and then the subviews are laid out perfectly. For example:
http://i.stack.imgur.com/jgjch.png
Within tableView: cellForRowAtIndexPath:
, I call [cell layoutIfNeeded]
before the method returns the cell. If I change this to [cell layoutSubviews]
, then the inverse happens, where the first batch of visible cells are laid out as they should be, but all of the cells that get loaded upon scrolling are not laid out properly.
I have tried to put [cell layoutIfNeeded]
within [tableview: willDisplayCell:
with no luck. Any ideas on how to fix this?
Thanks in advance!