Acctualy,我在这里看过很多教程,但它仍然没有用。我真的不知道为什么。我的iOS版本是9.1。现在我真的很讨厌取消按钮。
这是我在Viewdidload()
override func setViewWhenDidLoad() {
titleNoSearch.text = "Không có câu hỏi nào được tìm thấy"
//setup search bar
searchController.searchResultsUpdater = self
searchController.searchBar.placeholder = "Tìm theo mô tả trong câu hỏi hoặc đáp án"
definesPresentationContext = true
searchController.dimsBackgroundDuringPresentation = false
TableSearchView.tableHeaderView = searchController.searchBar
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.setShowsCancelButton(false, animated: false)
searchController.searchBar.showsCancelButton = false
searchController.delegate = self
searchController.searchBar.setShowsCancelButton(false, animated: false)
didPresentSearchController(searchController: searchController)
// content search
getContentSearchFullIndex()
}
func didPresentSearchController(searchController: UISearchController) {
searchController.searchBar.showsCancelButton = false
}
我尝试用另一种方法过载一些功能
class setUISearchBar: UISearchBar {
override func layoutSubviews() {
super.layoutSubviews()
setShowsCancelButton(false, animated: false)
}
}
class CustomSearchController: UISearchController, UISearchBarDelegate {
lazy var _searchBar: setUISearchBar = {
[unowned self] in
let result = setUISearchBar(frame: CGRect.zero)
result.delegate = self
return result
}()
override var searchBar: UISearchBar {
get {
return _searchBar
}
}
}