While i was updating my project to iOS 13 i faced an issue. I have logic for showing and handling some UISearchController actions (code below), all parts were working perfectly in iOS 11 & 12.
My task was to add search button at navigation bar to show UISearchController after button action.
But in iOS 13, i got 2 issues:Code that invokes from button actionfunc searchButtonTapped() { self.navigationItem.searchController = self.searchController self.definesPresentationContext = true self.searchController.isActive = true }Only one solution helps me to show search controller without any diffs from previous iOS versions.DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { searchController.isActive = true }Code that works on iOS 13, on iOS 11 and 12 code works without asyncAfterCode that helps me to hide UISearchController and set navigation bar initial state
in iOS 11 and 12, and not in 13. After tapping
cancel on SearchBar,
UISearchController begins to call delegate methods.
//MARK: UISearchControllerDelegate public func willDismissSearchController(_ searchController: UISearchController) { self.navigationItem.searchController = nil }BUTAfter setting navigationItem.searchController = nildidPresentSearchController calls twice and not only
UISearchController dismissed, but whole
UIViewController hierarchy right to
UIWindow. Or if i add
asyncAfter here i get normal dismiss with expanded nav bar height, that i don't need.
SOI think that asyncAfter in a dog-nail, how would you solve this problem?How can i dismiss UISearchController correctly?