简体   繁体   中英

UISearchController and NavigationBar back

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: 在此输入图像描述

And then press back: 在此输入图像描述

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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM