Search code examples
iosswiftuitableviewuicontainerview

Adjusting Container View's Height to Match Embedded UITableViewController


I'm implementing multiple uitableview in single view controller. now I want my container view same height as my embedded UITableView. How can i achieve it?enter image description here


Solution

  • I researched, I got pointed in the right direction - specifically, that this is not possible the way I thought it was.

    There is no way to have constraints between the views of a parent view controller and a child view controller - neither in IB, nor in code

    As far as I can see, there are two ways to solve this:

    Don't use a second UIViewController. Make the root view of your child view controller an actual subview of yourself, and just have a single UIViewController.

    Do not use auto layout. Manage the frame of your child view controller's view manually, and have delegate callbacks back to your parent view controller where necessary. In those delegate callbacks, your parent view controller can react to size changes of the child view controller's view.