title: Custom view in UITableView header overlapping UIViewController view
body: <p>I have a <code>UIViewController</code> that contains a <code>UITableViewHeaderFooterView</code> that has a <code>UIView</code> (SelectorDropDown)that, when the user clicks on it, expands another <code>UIView</code> (Belongs to SelectorDropDown). The idea can be thought as custom dropdown view and it looks like that:</p>
  
  <p><a href="https://i.stack.imgur.com/ZuHxh.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZuHxh.jpg" alt="enter image description here"></a></p>
  
  <p>The way I add the expandable view in my layout is by adding it in my <code>UIViewController</code> view despite belonging to the SelectorDropDown view inside my <code>UITableViewHeaderFooterView</code>. If I don't do it like that, the expandable view gets hidden. The function that handles the addition:</p>
  
  <pre><code>func setUpDropDown(with viewController:UIViewController){
  
      holderViewController = viewController
  
      //Adding drop drown view
      holderViewController!.view.addSubview(dropDrownView)
      holderViewController!.view.bringSubviewToFront(dropDrownView)
  
      dropDrownView.topAnchor.constraint(equalTo: bottomAnchor).isActive = true
      dropDrownView.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
      dropDrownView.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
      dropDrownView.backgroundColor = .red
      //dropDrownViewHeightConstraint = dropDrownView.bottomAnchor.constraint(equalTo: holderViewController!.view.bottomAnchor)
      dropDrownViewHeightConstraint = dropDrownView.heightAnchor.constraint(equalToConstant: 0)
      NSLayoutConstraint.activate([dropDrownViewHeightConstraint])
  
  }
  </code></pre>
  
  <p>However, ask expected, when I hide the <code>UITableView</code>, the expandable view stays because, in fact, belongs to the <code>UIViewController</code> view.</p>
  
  <p><a href="https://i.stack.imgur.com/zoRnp.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zoRnp.jpg" alt="enter image description here"></a></p>
  
  <p>Is there a way I can sort it?</p>
  
  <p>thanks </p>