title: SearchController not showing searchbar when wrapped in another view
body: <p>I have the following setup where the <code>Searchbar</code> in <code>SearchController</code> only gets visibility if directly added to the view ( not as a child of another view ). My setup,</p>
  <pre class="lang-swift prettyprint-override"><code>
      // The controller that initiates a search
  
      private lazy var searchResultViewController:
      ViewController = {
          let controller = SearchResultViewController.instantiate() // utility to instantiate from storyboard
          return controller
      }()
      
      private lazy var searchController: UISearchController = {
          let controller = UISearchController(searchResultsController: searchResultViewController)
          controller.showsSearchResultsController = true
          controller.definesPresentationContext = false
          controller.searchResultsUpdater = searchResultViewController
          controller.searchBar.delegate = searchResultViewController
          controller.searchBar.placeholder = &quot;Search&quot;
          controller.searchBar.setValue(&quot;Cancel&quot;, forKey: &quot;cancelButtonText&quot;)
          return controller
      }()
  </code></pre>
  <p>I am showing the <code>searchbar</code> in <code>tableView's</code> header.</p>
  <pre class="lang-swift prettyprint-override"><code>    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -&gt; CGFloat {
            return UITableView.automaticDimension
        }
  
        func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -&gt; CGFloat {
            return .leastNonzeroMagnitude
        }
  
        func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -&gt; UIView? {
            return searchController.searchBar 
            // If I pass it directly, the searchcontroller shows the searchbar
        }
  </code></pre>
  <p>Now, the problem is, I have a wrapper view around it like I want to have a filter button horizontally.</p>
  <pre class="lang-swift prettyprint-override"><code>    private lazy var headerStackView: UIStackView = {
          let searchBarView = searchController.searchBar
          let stackView = UIStackView(arrangedSubviews: [searchBarView, pickerButton])
          stackView.layoutMargins = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
          stackView.isLayoutMarginsRelativeArrangement = true
          stackView.distribution = .fill
          stackView.backgroundColor = .white
          stackView.spacing = 0
          stackView.alignment = .fill
          stackView.axis = .horizontal
          return stackView
      }()
  </code></pre>
  <p>Now if I pass this as header view,</p>
  <pre class="lang-swift prettyprint-override"><code>     func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -&gt; UIView? {
            return headerStackView // It does not show when searchcontroller opens
        }
  </code></pre>
  <p>So, when <code>searchController</code> opens the <code>searchResultController</code> the <code>searchBar</code> only gets visibility if it doesn't get wrapped in another view.</p>
  <p>Any insight?</p>