1

I have next structure of views:

vc
-view
--safe area
--scrollview
---view
----containerview1
----containerview2
----containerview3
-----tableviewcontroller(in containervew3)

Tableviewcontroller has buttons which add or remove rows, I want to resize scroll view that it shows full tableview content(without scrolling in tableview). I tried to solution like: from here or Sizing a Container View with a controller of dynamic size inside a scrollview but without success. I use iOS 10.0&swift

Saveen
  • 4,120
  • 14
  • 38
  • 41

1 Answers1

0

First thing is constraints. You must have proper constraints with UIScrollView and container's view

Next thing you need is height constraints of tableviewController (you can give height to 0 with relation greater than equal with 750 priority so constrains would never break if something wrong happened)

Take IBOutlet of that height constraint when your data insert / delete happen your content size will change and apply that contentsize height to constant of IBOutlet constraint and don't forgot to layoutIfNeeded.

Make your tableview scrolling bounce to false

create protocol to notify container view about height change

protocol ContainerTableDelegate {
      func dataChanged(height: CGFloat)
 }

and when height change notify parent view controller

    delegate?.dataChanged(self.heightConstraint.constant)

Now in the main viewcontroller where you have all containers

implement

 override func prepare(for segue: UIStoryboardSegue, sender: Any?) 

identify ViewController set delegate to self implement delegate and change height of container view 3 constant (You also need this)

Hope it will help to solve your issue

Prashant Tukadiya
  • 15,838
  • 4
  • 62
  • 98
  • Thank for response Prashant Tukadiya, but unfortunately, container view does not change its size, I tried also make it bigger than needed by multiply , delegate works, constraint sets, layoutIfNeeded also calls(I checked it by manually making scrollview content size bigger in function which applies new height) also I tried to add tableviewController.view.translatesAutoresizingMaskIntoConstraints = false but without success – Anton Lisitsyn Dec 28 '17 at 20:01
  • @AntonLisitsyn I have created UIView and give height constraint to it. in that view i have added container view. on some button even I am changing height constraints's constant value and accordingly container view also changes. So It should work – Prashant Tukadiya Dec 29 '17 at 10:57