【问题标题】:UISearchController.isActive is showing false while editing in searchbar?UISearchController.isActive 在搜索栏中编辑时显示错误?
【发布时间】:2017-06-23 10:41:16
【问题描述】:

我在集合视图控制器上方添加了一个搜索栏。在激活搜索控制器时,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)
}

【问题讨论】:

  • 你能发布你的代码吗?

标签: ios swift3 uicollectionview uisearchcontroller uisearchresultscontroller


【解决方案1】:

确保在这两种情况下您的实例变量都包含相同的UISearchcontroller 对象。通过在两种情况下打印对象地址。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-06
    • 2017-03-03
    • 1970-01-01
    • 2021-01-25
    • 1970-01-01
    相关资源
    最近更新 更多