1

I am trying to expand my view when tableViewCells are added to the tableview to scroll the whole view rather than the table, but my implementation of increasing the size of the tableView and the ScrollView isn't quite working, I'm not sure if it has something to do with the code or the constraints set. What sort of constraints would I have to set in story board to make this work?

This is what I've tried and it isn't expanding the scroll view:

@IBAction func addExercisePressed(_ sender: Any) {
        test.append("nice")
        tableView.isScrollEnabled = false
        tableView.frame = CGRect(x: tableView.frame.origin.x, y: tableView.frame.origin.y, width: self.view.frame.size.width, height: CGFloat(tableView.visibleCells.count * 120))
        scrollView.contentSize = CGSize(width: self.view.frame.size.width, height: tableView.frame.size.height)
        tableView.reloadData()
    }
Noah Iarrobino
  • 1,435
  • 1
  • 10
  • 31

1 Answers1

0

tableView.visibleCells.count isn't the same as number of cells at some time , also you need to use auto-layout constraints by giving the table in IB a default height and hooking it as an IBOutlet then inside viewDidLayoutSubviews/viewDidAppear do

 self.tableHeight.constant = numOcells * 120
 self.view.layoutIfNeeded() 
Shehata Gamal
  • 98,760
  • 8
  • 65
  • 87