I am using searchBar and when I select to search , it workes just fine (besides this runtime warning that I can't fix Attempting to load the view of a view controller while it is deallocating... UISearchController)
But if the searchBar isActive and I press "Back" from the NavBar , the parentView is presented but the searchBar from the previous screen is also visible. I tried dismissing the searchBar if the "Back" button is pressed but it is still visible for some time. I am thinking about
self.navigationItem.backButtonItem.enabled = false
while searchBar is active , but I don't like this solution
my code (I also have func updateSearchResultsForSearchController) :
class ViewController: UIViewController ,UISearchResultsUpdating {
var resultSearchController = UISearchController()
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 9.0, *) {
self.resultSearchController.loadViewIfNeeded()// iOS 9
} else {
// Fallback on earlier versions
let _ = self.resultSearchController.view// iOS 8
}
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.hidesNavigationBarDuringPresentation = false
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
The runtime warning (not sure if that's the issue here)
Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<UISearchController: 0x7ff88130fdb0>)