【发布时间】:2017-03-18 03:36:38
【问题描述】:
我按照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
}
}
}
这是我从viewDidLoad() 调用的addSearchController 方法
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
}
有没有人遇到过这种情况?谢谢:)
【问题讨论】: