title: Gap between navigation bar and first UITableViewCell
body: <p>I have a UITableViewController with a search controller embedded in the navigation bar.</p>
  <p>When the view shows in a modal, there is a gap between the first row and the navigation bar.</p>
  <p><a href="https://i.stack.imgur.com/MO11t.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MO11t.jpg" alt="enter image description here" /></a></p>
  <p>here is my implementation. Some code has been redacted for confidentiality. But anything regarding view controller setup should still be there:</p>
  <pre><code>import Foundation
  
  class SearchViewController: UITableViewController {
  
      fileprivate lazy var searchController: UISearchController = {
          let searchController = UISearchController(searchResultsController: nil)
          searchController.dimsBackgroundDuringPresentation = false
          searchController.hidesNavigationBarDuringPresentation = false
          searchController.searchBar.showsCancelButton = true
          searchController.searchBar.delegate = self
          return searchController
      }()
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          setupTableView()
  
          navigationItem.titleView = searchController.searchBar
      }
  
      override func viewWillDisappear(_ animated: Bool) {
          super.viewWillDisappear(animated)
          navigationController?.navigationBar.tintColor = BrandColor.appleDarkGray
      }
  
  }
  
  extension ExploreSearchViewController: UISearchBarDelegate {
  
      func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
          presentingViewController?.dismiss(animated: true, completion: nil)
      }
  
      func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
          if let searchText = searchBar.text {
              tableView.refreshControl?.beginRefreshing()
              searchedText = searchText
          }
      }
  }
  
  // MARK: - UITableView Methods
  extension ExploreSearchViewController {
      override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
          return searchResultsProvider.searchResults.count
      }
  
      override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
          guard searchResultsProvider.canLoadNextPage else { return }
  
          // handle paging here...
      }
  
      override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
          guard searchResultsProvider.searchResults.count &gt; indexPath.row else { return UITableViewCell() }
  
          // Setup search result cell here...
      }
  
      override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
          // Handle cell did tap here...
      }
  
      @objc private func refresh() {
          searchResultsProvider.refreshResults()
      }
  
      // MARK - Table View Helpers
  
      private func setupTableView() {
          registerCells()
          self.tableView.backgroundColor = .white
          self.tableView.contentInsetAdjustmentBehavior = .always
          self.tableView.refreshControl = UIRefreshControl()
          self.tableView.refreshControl?.addTarget(self, action: #selector(refresh), for: .valueChanged)
          self.tableView.useDefaultPageLoadingIndicator()
          self.tableView.setBackgroundViewIfEmpty(message: Self.searchInitialMessage, remedyButton: nil)
      }
  
      private func registerCells() {
          //Register Table View Cells here...
      }
  }
  </code></pre>
  <p>Has anyone seen this kind of issue before? I can't move the top edge insets up because then the refresh control will be hidden behind the navigation bar.</p>
  <p>Anyone seen this behaviour before? If so, how did you solve it?</p>