dgu*_*taf 22 uisearchbar ios swift ios8 uisearchcontroller
我的目标是阻止取消按钮出现在UISearchController的搜索栏中.我从Apple的Table Search开始,使用UISearchController示例代码并隐藏了取消按钮,如下面的代码片段所示.但是,当用户点击文本字段时,仍会显示取消按钮.有帮助吗?
override func viewDidLoad() {
super.viewDidLoad()
resultsTableController = ResultsTableController()
searchController = UISearchController(searchResultsController: resultsTableController)
searchController.searchResultsUpdater = self
searchController.searchBar.sizeToFit()
tableView.tableHeaderView = searchController.searchBar
searchController.searchBar.delegate = self
//Hide cancel button - added by me
searchController.searchBar.showsCancelButton = false
...
Run Code Online (Sandbox Code Playgroud)
nun*_*des 20
我认为有三种方法可以实现这一目标:
searchController.searchBar.showsCancelButton = false
子类UISearchBar并覆盖layoutSubviews以在系统尝试绘制var时更改该var.
注册键盘通知UIKeyboardWillShowNotification并应用第1点中的代码.
当然可以随时实现您的搜索栏.
And*_*son 17
对于iOS 8和UISearchController,请使用以下的委托方法UISearchControllerDelegate:
func didPresentSearchController(searchController: UISearchController) {
searchController.searchBar.showsCancelButton = false
}
Run Code Online (Sandbox Code Playgroud)
不要忘记将自己设置为代表: searchController.delegate = self
ma1*_*w28 14
简单地子类化UISearchController&UISearchBar.
class NoCancelButtonSearchController: UISearchController {
let noCancelButtonSearchBar = NoCancelButtonSearchBar()
override var searchBar: UISearchBar { return noCancelButtonSearchBar }
}
class NoCancelButtonSearchBar: UISearchBar {
override func setShowsCancelButton(_ showsCancelButton: Bool, animated: Bool) { /* void */ }
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16969 次 |
| 最近记录: |