Autolayout UIScrollView to match content, including subitems and grouped tables

I am trying to present information about an object grouped by sections. It can be long, so each section uses a view to visually separate the areas, and all this is in scroll mode.

The first view has a text box that resizes to fit the text, and its parent view also resizes to fit the text box.

The second view has a pivot table for displaying data. I want all the data in the table to be displayed and there is no scrolling of the table.

There is more information in the third review, but its contents are an empty representation for the purposes of this demonstration. In a real application, I can add an arbitrary number of custom subqueries.

What I find is that the first subview resizes accordingly, but I cannot find a combination of layout constraints that will make the second size of the subview suitable for the table and shift the third view down.

What do I need to do so that the scroll view matches its contents when the contents of the subtitle can change? The table view fills the available space in the parent view, but the parent view does not expand to fit. I note that the third view has a top space constraint for the supervisor, and not just for presentation above it. This can be seen in the screenshot below.

layout and simulator

+4
source share
1 answer

I found a solution similar to most solutions seems retrospective.

I think my problem is that the inner table did not have a fixed height, and since it was also a scrollview, it tried to shift everything that was assigned, rather than expand to fit the internal content. I was able to solve my problem by adding a fixed height limit in IB and plugging it into a power outlet in the view controller. Then in the controller:

-(void) viewWillLayoutSubviews{ [self.tableView layoutIfNeeded]; self.tableViewHeightConstraint.constant = self.tableView.contentSize.height; } 

Derp. Thus, the presentation of the table required height, so I set it.

Here's a screenshot, note the fixed height limit on the right: properly scrolling view

+9
source

All Articles