Reputation: 79
I have a problem with the UISearchController in combination with UITabBarController. I have 3 tabs. In every tab, I have an UITableViewController with a search bar from UISearchController set as header view of the table view as follows.
searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = true
tableView.tableHeaderView = searchController.searchBar
tableView.contentOffset = CGPointMake(0, CGRectGetHeight(searchController.searchBar.frame))
If I start searching and switch to the other tab without canceling the search and then return back to previous tab, the content of the UITableView become black. I have read multiple postings such as UISearchController makes the controller black or UISearchController causes black screen Swift 2.0. But these solutions do not work for me. If I am setting
definesPresentationContext = true
then the problem first occur. If I omit this line then the content of the table view are not becomming black but the search bar stay activated in a searching state on the next tab. I also tried setting searchResultsController to another UITableViewController but it does not solve the problem too.
Upvotes: 1
Views: 699
Reputation: 2096
I too faced the same problem,fixed by just adding the following line in viewDidDisappear
self.searchController.active = false
Usually, you get the value of this property to determine whether the search results are displayed. However, you can set this property to true to force the search interface to appear, even if the user has not taps in the search field.
The default value of this property is false.
false
if user interacts with searchController
it switches to true.UISearchController
is active.So we need to simply deactivate programatically while switching to other VC.Upvotes: 0