swift - 将 searchBar 添加到 tableHeaderView 会增加底部空白
问题描述
我需要补充一点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
但是,此解决方案在UIViewController
not the not the athkarSearchTable
not good :/底部添加了一个空白区域,如下面的屏幕截图:
我试图将页脚设置为空视图并将页脚的高度设置为零,但它们都不起作用:/
任何建议如何删除底部的空白空间?
解决方案
通过添加以下行解决了问题:
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 400
推荐阅读
- javascript - Babel Compile 停止命令链
- javascript - 检查号码的前缀
- c# - 在哪里放置 tesseract 语言文件以及数据路径字符串是什么样的?
- javascript - 我的 javascript 处理我的表单并重定向我,但它没有在它重定向到的 php 文件中发布输入值
- amazon-web-services - 如何在不破坏 API 网关的情况下使用无服务器框架
- xquery - 在 MarkLogic 上使用 xquery 连接字符串、fn:concat 还是管道 (||) 连接更快?
- vue.js - echarts如何在每个圆环图切片上显示数据值
- python - 如何在 python 中捕获 socket.io 异常
- python-3.x - 在 Odoo 记录中发送电子邮件不存在
- ios - 如何在 tableview Swift 中获取选中标记的行列表?