我在集合视图控制器上方添加了一个搜索栏。在激活搜索控制器时,UISearchcontroller.isActive返回“ true ”,但在编辑时返回“ false ”。但在 tableview 控制器中,相同的实现工作正常。谁能解释一下是什么原因以及如何解决?
var resultSearchController = UISearchController()
func viewdidLoad() {
self.resultSearchController = UISearchController(searchResultsController: nil)
self.resultSearchController.searchResultsUpdater = self
self.resultSearchController.searchBar.delegate = self
self.definesPresentationContext = true
self.resultSearchController.dimsBackgroundDuringPresentation = false
self.resultSearchController.searchBar.placeholder = "Search for Stores"
self.resultSearchController.searchBar.searchBarStyle = UISearchBarStyle.prominent
self.resultSearchController.searchBar.sizeToFit()
collectionView?.delegate = self
collectionView?.dataSource = self
}
func updateSearchResults(for searchController: UISearchController) {
print(self.resultSearchController.isActive)
}