Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 857
Arnaud Moret Avatar asked May 23 '15 07:05

Arnaud Moret


1 Answers

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

like image 98
Clinton D'Souza Avatar answered Oct 28 '22 23:10

Clinton D'Souza