Reputation: 337
I have looked at other answers to this problem but they did not solve my problem.
This is my storyboard setup:
In my UITableViewController, if I set self.definesPresentationContext = true
then the search bar will appear on every tab. If I don't, then the table will turn black after clicking search then switching to another tab and switching back.
Workaround 1: Dismiss searchController or set isActive to false in viewWillDisappear
.
Problem: The search bar gets push down from the top every time I switch back and forth:
Workaround 2: Set searchController.searchBar.isHidden = true
.
Problem: In my other tab which also uses UISearchController
, it's not able to present the scope due to another search bar being already present (but hidden):
Attempt to present <UISearchController: 0x7ff81ac0aa30> on <xxx.ViewController: 0x7ff81ac0a6f0> which is already presenting (null)
Upvotes: 1
Views: 1716
Reputation: 492
Using your Workaround 1, setting self.searchController!.isActive = true
in viewDidAppear
does the magic. You'd also need to restore the search bar text though.
Upvotes: 0
Reputation: 20804
I was having the same problem and was fixed, handling correctly the definesPresentationContext
properly, so I just define this property to true in viewDidAppear
and set it false
in viewWillDisappear
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
if(self.searchController == nil)
{
self.setupSearchBar()
}else{
self.definesPresentationContext = true
}
}
override func viewWillDisappear(_ animated: Bool) {
self.searchController!.isActive = false
self.searchController!.searchBar.removeFromSuperview()
self.definesPresentationContext = false
if(self.showingSearchBar)
{
self.rigthNavBarButtonAction()
}
super.viewWillDisappear(animated)
}
I hope this helps you
Upvotes: 1