0
votes

I am facing a trouble with UIScrollView using auto layouts. I have the following view hierarchy with constraints.

  • ViewA (leading,trailing,top and bottom spaces to superview).

    -- ViewB (leading,trailing,top and bottom spaces to superview).

    --- UIScrollView (leading,trailing,top and bottom spaces to superview).

Here ViewB is adding on ViewA and i have some textfields,buttons and UITableview these all are placed inside UIScrollView.This is my view hierarchy.

Now i want to my Scrollview height increase dynamically based on tableview number of rows.

For this I'm using bellow code but it not working.Can any one please suggest me.

CGFloat height = MIN(self.view.bounds.size.height, placeTbl.contentSize.height);
self.Height_PlaceTbl.constant = height;  
[self.view layoutIfNeeded];
1
Set all the vertical constraints in scrollview content view and create outlet of tableview height constraint. Calculate height of tableview programmatically from row height and number of items and set it to table view height constraint, it should update the scrollview's content height.Sajad Khan

1 Answers

0
votes

if you want to increase your ScrollView height based on tableview number of rows you can try this first get number of your tableview rows and then get height and width of your scrollview

let width = self.scrollview.layer.bounds.width
let height = self.scrollview.layer.bounds.height

after this , you can increase height of your scrollview like this

self.scrollview.frame = CGRectMake(0, 0, width, height + numberofrows)