Arnaud Moret
Arnaud Moret

Reputation: 753

The navigation bar disappears in the search result table view

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

Upvotes: 6

Views: 2075

Answers (1)

Clinton D&#39;Souza
Clinton D&#39;Souza

Reputation: 301

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

Upvotes: 2

Related Questions