我已将 UISearchController 添加到我的应用程序中,并将其 searchBar 设置为titleView
of my navigationItem
.
这有效,但我看到取消按钮,尽管已经设置showsCancelButton
to false
.
searchController = UISearchController(searchResultsController: searchResultsController)
searchController.searchResultsUpdater = searchResultsUpdater
// Configure the searchBar
searchController.searchBar.placeholder = "Find Friends..."
searchController.searchBar.sizeToFit()
searchController.searchBar.showsCancelButton = false
self.definesPresentationContext = true
navigationItem.titleView = searchController.searchBar
我同意,这似乎是一个错误。问题是searchController
不断重置showsCancelButton
搜索栏的属性。我找到了一个解决方案,涉及:
- 子类化
UISearchBar
忽略setShowsCancelButton
.
- 要使 searchController 使用该子类,您必须子类化
UISearchController
.
- 然后你发现 searchBar 没有触发搜索控制器的委托方法,所以你必须单独触发它们......
很复杂,但似乎可以解决问题。你可以找到完整的在这里回答 https://stackoverflow.com/a/28396967/3985749.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)