【发布时间】:2019-06-09 07:32:24
【问题描述】:
我需要将UISearchController 添加到UIViewController 我知道最好的方法是将其添加到UINavigationController,如下所示:
let resultSearchController = UISearchController(searchResultsController: athkarSearchTable)
resultSearchController?.searchResultsUpdater = athkarSearchTable
navigationItem.searchController = resultSearchController
问题是我无法使用UINavigationController,所以我找到了另一个解决方案:将其添加到tableHeaderView,如下所示:
let resultSearchController = ({
let controller = UISearchController(searchResultsController: athkarSearchTable)
controller.searchResultsUpdater = athkarSearchTable
// to give a semi-transparent background when the search bar is selected.
controller.dimsBackgroundDuringPresentation = true
controller.searchBar.sizeToFit()
controller.searchBar.barStyle = UIBarStyle.default
controller.searchBar.searchBarStyle = .minimal
tableView.tableHeaderView = controller.searchBar
return controller
})()
// to limit the overlap area to just the View Controller’s frame instead of the whole Navigation Controller
definesPresentationContext = true
但是,此解决方案在UIViewController 中的tableView 底部添加了一个空白空间,而不是athkarSearchTable,这不好:/ 如下截图:
我尝试将页脚设置为空视图并将页脚的高度设置为零,但它们都不起作用:/
有什么建议可以去掉底部的空白吗?
【问题讨论】:
标签: swift uitableview uisearchcontroller