使用 ios 8 UISearchController 单击搜索栏时如何隐藏部分标题?
how to hide the section title when clicked search bar using ios 8 UISearchController?
这是上一个屏幕。
然后,我点击了搜索栏:
代码如下:
// 标记:- searchController
func initSearchController() {
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.backgroundColor = UIColor.clearColor()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
}
请帮助我。谢谢
将节的标题设置为 nil,如果该节中没有行,这将隐藏节标题
// Set the title of the section header, return nil if no rows in that section
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if self.tableView(tableView, numberOfRowsInSection: section) == 0 {
return nil
} else {
return "section title \(section)"
}
}
这将有效,假设 tableView(tableView: UITableView, numberOfRowsInSection section: Int)
已正确实施以反映基于搜索结果的部分数量。
如果您想在搜索栏处于活动状态时完全删除部分标题,则只需添加此
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if self.resultSearchController.active {
return nil
} else {
return "section title \(section)"
}
}
然后,我点击了搜索栏:
代码如下: // 标记:- searchController
func initSearchController() {
self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.backgroundColor = UIColor.clearColor()
self.tableView.tableHeaderView = controller.searchBar
return controller
})()
}
请帮助我。谢谢
将节的标题设置为 nil,如果该节中没有行,这将隐藏节标题
// Set the title of the section header, return nil if no rows in that section
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if self.tableView(tableView, numberOfRowsInSection: section) == 0 {
return nil
} else {
return "section title \(section)"
}
}
这将有效,假设 tableView(tableView: UITableView, numberOfRowsInSection section: Int)
已正确实施以反映基于搜索结果的部分数量。
如果您想在搜索栏处于活动状态时完全删除部分标题,则只需添加此
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if self.resultSearchController.active {
return nil
} else {
return "section title \(section)"
}
}