3

I try add UISearchBarController to tableView, but when i set UINavigationBar.appearance().translucent = false then UISearchBar hide out of screen

in TableViewController

var resultSearchC: UISearchController = UISearchController()

override func viewDidLoad() {
    super.viewDidLoad()

    self.resultSearchC = ({
        let c = UISearchController(searchResultsController: nil)
        c.searchResultsUpdater = self

        c.searchBar.translucent = true

        c.searchBar.barTintColor =  .redColor()
        c.searchBar.sizeToFit()

        self.tableView.tableHeaderView = c.searchBar

        return c
    })()

    // self.edgesForExtendedLayout = .None

    self.tableView.reloadData()
}

AppDelegate:

let navBarAppearance = UINavigationBar.appearance()

    navBarAppearance.barStyle = .Black
    navBarAppearance.translucent = false
moto0000
  • 101
  • 8

1 Answers1

9

You need to set extendedLayoutIncludesOpaqueBars to true in viewDidLoad().

extendedLayoutIncludesOpaqueBars = true;
jcislinsky
  • 141
  • 1
  • 2
  • 2
    You have to write it in your UINavigationController subclass, not in your active view controller – Artem Deviatov Mar 29 '16 at 19:07
  • @ArtyomDevyatov @Andrespch For iOS10 and iOS11, no need to subclass UINavigationController, you can just do: `let navVC = UINavigationController(rootViewController: rootVC) navVC.extendedLayoutIncludesOpaqueBars = true` – Eugene Brusov Oct 03 '17 at 15:18