I'm trying to do the following in my iOS app:
- Embed a
UITableView
into a parent scroll view; the table view will have its frame expanded to show all its contents (I need to do this because the table view data is a small component of a much larger more complex screen, and I don't want nested scrolling behavior) - I have different layouts for iPhone and iPad, so the cells in this table view are using size classes defined in a table view cell xib.
- Since I want the content size of the table view to be accurate, I don't think I can use
UITableViewAutomaticDimenstion
as the rowheight, so I implementtableView:heightForRowAtIndexPath:
and load an instance of my tableview cell from the nib directly and store that view as a property with which I can figure out how tall the cell should be according to autolayout.
My problem stems here; when I load the cell directly from the nib, on iPad the cell uses the constraints and layout in the 'Any' size class as defined in the nib, which is incorrect because the iPad's layout uses the regular width class only in my nib. This causes my table view cell heights to be wrong and too large in my case.
What I need to know is if there's a way to force the trait collection on the cell I load, such that the proper constraints for my views are used on each device type. I can't seem to find anything in the docs that allows for this directly in UIView
s, only in UIViewController
s and I'm not keen on holding an offscreen UITableViewCell
in a random offscreen UIViewController
if i can help it. Any ideas?