1
我按照this post中的重要方向对搜索栏和不显示取消按钮的搜索控制器进行了子类化。但是,当我开始编辑时,我的搜索栏中现在没有光标。我已经尝试设置搜索栏的色调,我已经在许多帖子中以各种代理方法看到了这一点。色彩在技术上正确设置,因为我可以通过将我的搜索控制器设置为标准UISearchController
进行测试时看到。但是,只要我将它设置为我的子类SearchControllerWithoutCancel
,光标就会消失。隐藏取消按钮时搜索光标消失
这里是我的子类:
class SearchBarWithoutCancel: UISearchBar {
override func layoutSubviews() {
super.layoutSubviews()
setShowsCancelButton(false, animated: false)
}
}
类SearchControllerWithoutCancel:UISearchController,UISearchBarDelegate {
lazy var _searchBar: SearchBarWithoutCancel = {
[unowned self] in
let result = SearchBarWithoutCancel(frame: .zero)
result.delegate = self
return result
}()
override var searchBar: UISearchBar {
get {
return _searchBar
}
}
}
这是我的addSearchController
方法,这是我从viewDidLoad()
打电话
func addSearchController() {
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.autocapitalizationType = .none
searchController.searchBar.searchBarStyle = .minimal
searchController.searchBar.tintColor = UIColor.black
self.definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
}
有没有人遇到过这个?谢谢:)