1
votes

This is my ViewController in the storyboard:

UIView (Controller)
-UIScrollView
--UIView
--UIView
--ContainerView
---UITableView (Embedded inside ContainerView)

The UITableView has dynamic prototypes.
My question is how do I change the UIScrollView and ContainerView's height to adapt to the UITableView's number of rows?

I want to be able to scroll down with my UIScrollView(not the UITableView's UIScrollView), when there are many rows inside the UITableView.

2

2 Answers

1
votes

You can apply below logic to increase the height of scroll view.

height = Total number of rows (array or dictionary count) * your cell height (cell height should be static).

Using below calculation you will find the total height and set this height as a table height or scroll view height.

[scrollview setContentSize:CGMakeSize(scrollview.contentSize.width,tableView.frame.size.height)];

OR

[scrollview setContentSize:CGMakeSize(scrollview.contentSize.width,height)];

I hope this is work for you.

Thanks

1
votes

Just update the contentSize of the UIScrollView every time there is a change in the number of rows.

Look at the example below:

- (void)updateScrollViewContentSize
{
    float cellHeight = 40;
    int numberOfRows = [noOfItemsInArray count];

    float sizeOfContent = cellHeight * numberOfRows;

    scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, sizeOfContent);
}