Attempting to load the view of a view controller while it is deallocating… UISearchController

前端 未结 13 1160
一生所求
一生所求 2020-12-01 02:34

I have code that creates a UISearchController\' in my UIVIew\'sviewDidLoad`.

 self.resultSearchController = ({
        let controller = UISearch         


        
13条回答
  •  甜味超标
    2020-12-01 03:07

    Mine is working like this

    func initSearchControl(){
    
            searchController = UISearchController(searchResultsController: nil)
    
            if #available(iOS 9.0, *) {
                searchController.loadViewIfNeeded()
            } else {
                let _ = self.searchController.view
            }
    
            searchController.searchResultsUpdater = self
            searchController.dimsBackgroundDuringPresentation = false
            definesPresentationContext = true
            tableView.tableHeaderView = searchController.searchBar
            searchController.searchBar.sizeToFit()
        }
    

    searchController.loadViewIfNeeded() solves the problem but you need to call it after initializing the searchController

提交回复
热议问题