title: Dynamic table view + scroll view
body: <p>I've got a <code>UIScrollView</code>, on the top there are some information sources and on the button there is a a <code>UITableView</code>. The table view cannot be scrolled, so to be capable of displaying a large number of cells I need to do the manual calculation stuff. That's what I actually do (you can see in the code below). Meanwhile, the container for the table view should also grow with it. I try to change these parameters while loading a view but nothing really changes... </p>
  
  <p>This is how it looks like. In the IB. </p>
  
  <p><img src="https://i.stack.imgur.com/mumpk.png" alt="enter image description here"></p>
  
  <p>The struct.</p>
  
  <p><img src="https://i.stack.imgur.com/Ehw2a.png" alt="enter image description here"></p>
  
  <p>And the code.</p>
  
  <pre><code>class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
      @IBOutlet var scrollView: UIScrollView!
      @IBOutlet var tableView: UITableView!
  
      let numberOfCells = 55
      let rowHeight: CGFloat = 40
      let footerHeight: CGFloat = 30
      let headerHeight: CGFloat = 30
  
      let identifier = "Cell"
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          self.tableView.dataSource = self
          self.tableView.delegate = self
          self.tableView.backgroundColor = self.view.backgroundColor
          self.tableView.scrollEnabled = false
  
          self.automaticallyAdjustsScrollViewInsets = false
          self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: self.identifier)
  
          let estimatedHeight = CGFloat(self.numberOfCells) * self.rowHeight + self.footerHeight + self.headerHeight
          self.tableView.frame.size = CGSizeMake(self.tableView.bounds.width, estimatedHeight)
          self.scrollView.contentSize = CGSizeMake(self.view.bounds.width, CGRectGetMaxY(self.tableView.frame))
          self.scrollView.frame.size = CGSizeMake(self.view.bounds.width, CGRectGetMaxY(self.tableView.frame))
      }
  
      // MARK:- Table view data source
  
      func numberOfSectionsInTableView(tableView: UITableView) -&gt; Int {
          return 1
      }
  
      func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return self.numberOfCells
      }
  
      func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {
          let cell = tableView.dequeueReusableCellWithIdentifier(self.identifier) as UITableViewCell
  
          cell.textLabel?.text = "City"
          cell.accessoryType = UITableViewCellAccessoryType.DisclosureIndicator
  
          return cell
      }
  
      // MARK:- Table view delegate
  
      func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
          tableView.deselectRowAtIndexPath(indexPath, animated: true)
      }
  
      func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -&gt; CGFloat {
          return self.rowHeight
      }
  
      func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -&gt; CGFloat {
          return self.headerHeight
      }
  
      func tableView(tableView: UITableView, heightForFooterInSection section: Int) -&gt; CGFloat {
          return self.footerHeight
      }
  }
  </code></pre>
  
  <p>So, what could be the reason? How to make what I want? Frankly, I don't feel quite familiar with UIScrollView but with a few tutorials the image got constructed. </p>