I am trying to have a UISearchController in the navigation bar and display the results in an external controller.
For some reason the navigation bar disappear as soon as I type something in
I have been trying different solutions for a few hours with no results. It looks like it is a similar issue as Navigation bar disappears when typing in UISearchController text field and Navigation bar disappears if reload data with UISearchController that did not get any answer.
self.cearchController = ({
//creating another tableview
let storyBoard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let alternateController:SearchResultsTableViewController = storyBoard.instantiateViewControllerWithIdentifier("SearchResultsTableViewController") as! SearchResultsTableViewController
let controller = UISearchController(searchResultsController: alternateController)
controller.hidesNavigationBarDuringPresentation = false
controller.dimsBackgroundDuringPresentation = false
controller.searchResultsUpdater = alternateController
controller.searchBar.sizeToFit()
controller.searchBar.placeholder = "Search"
self.navigationItem.titleView = controller.searchBar
return controller
})()
I have tried
self.navigationController?.setNavigationBarHidden(true, animated: false)
and I have
myResultsTableView.definesPresentationContext = true
in the viewdidload
this is what it looks like :
Note: I have only started with swift a few days ago so I might be missing something really obvious!!
Thanks and happy to add more code
So I had a similar issue of the navbar disappearing when my search results were shown. But controller.hidesNavigationBarDuringPresentation = false did the trick for me.
Maybe try using tableView.tableHeaderView = searchController.searchBar instead of self.navigationItem.titleView = controller.searchBar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With