How to dynamically increase height of scrollview based on uitableview

Viewed 4679

Currently, I've developed project that UIScrollView, UITableView, another 3 more UIView inputs and UIButton at the last. In that page, UIScrollView height will be dynamically increased based on height of UITableView.

For UITableView there is no more scrolling. Its height will be increased as well based on how many rows are added based on JSON data loaded by Async as follow.

productHeight = 44;
productHeight *= _nsOrderItems.count;
productHeight = productHeight + 100;

if (isHeaderTap) {
    self.productTableHeight.constant = 50;
} else {
    self.productTableHeight.constant = productHeight;
}

//then the tableView must be redrawn
[self.productTable setNeedsDisplay];

My Problem is I want to increase height of UIScrollView based on height of UITableView.

- (void)viewDidLayoutSubviews {
    [self.scrollView setContentSize:CGSizeMake(_scrollView.frame.size.width, _btnEdit.frame.origin.y + _btnEdit.frame.size.height)];
}
2 Answers
// Get the supposed to be height of tableview 
CGFloat height = self.tableViewMenu.contentSize.height;
 // get the height constraint of tableview and give it you respected height
self.constraintHeightTableView.constant = height;
    // set the scroll 

NOTE:- don't forget to disenable the scrolling of table from storyboard or programmatically

self.scrollView.contentSize = CGSizeMake(self.scrollView.contentSize.width, self.viewUserLogin.frame.size.height + height);
    [self.scrollView layoutIfNeeded];
Related