3
votes

I'm addapting this code in my project https://github.com/stuartbreckenridge/UISearchControllerWithSwift

After Navigation Controller and before Countries Scene (ViewController) I have put one more View Controller, so now in Countries View controller I have back button. After inputing something in search bar when I press Back, search bar still is visible.

I've tried hide it doing this (countrySearchController is UISearchController):

override func viewWillDisappear(animated: Bool) {
    self.countrySearchController.active = false
}

But it hides UISearchController with delay, so it's stil visible for half a second.

Input something: enter image description here

And then press back: enter image description here

1
How did you solve it? - S.Philip

1 Answers

4
votes

Correct way probably is to set self.definesPresentationContext in viewDidLoad

self.definesPresentationContext = true

That caused some glitches when UISearchController became active, so I just removed the searchBar from Superview.

override func viewWillDisappear(animated: Bool) {
    searchController.searchBar.removeFromSuperview()
    searchController.active = false;
    super.viewWillDisappear(true)
}