我需要将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
但是,此解决方案在tableView
的{{1}}底部而不是UIViewController
的底部athkarSearchTable
的底部添加了一个空白:
我试图将页脚设置为空视图,并将页脚的高度设置为零,但没有一个起作用:/
任何建议如何删除底部的空白空间?
答案 0 :(得分:0)
通过添加以下行来解决问题:
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 400