Reputation: 164
I configure a search controller in a view controller:
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.placeholder = getLocalizedString("searchByName")
searchController.searchBar.setValue(getLocalizedString("cancel"), forKey:"_cancelButtonText")
searchController.searchBar.delegate = self
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.showsCancelButton = true
searchController.searchBar.sizeToFit()
Then, when a search button in navigation bar is clicked, I present the search bar in the navigation bar's titleView:
self.navigationItem.setHidesBackButton(true, animated: true)
self.navigationItem.rightBarButtonItem = nil
self.navigationItem.leftBarButtonItem = nil
self.navigationItem.titleView = searchController.searchBar
searchController.searchBar.becomeFirstResponder()
When I use this view controller as a tab bar item, the search bar works as expected.
I also reuse the view controller with a segue from another view controller which also have a search controller.
After the segue is performed, and I click the search button, the search bar is presented but is not responding to clicks or anything.
Update
I just figured out it's because I'm using:
self.definesPresentationContext = true
Any idea why? I need it because if not the screen is blacked out if I'm moving between tabs.
Thanks.
Upvotes: 0
Views: 299
Reputation: 164
For people looking for answer, I was able to fix it by setting definesPresentationContext
to false in prepareForSegue
method.
Also to avoid a black screen when the user segue back I also set it back to true in viewWillAppear
.
Upvotes: 2