ios - UISearchController 重叠 TableView 的 ScrollView 。解决这个问题的最佳方法是什么?

标签 ios swift uitableview uisearchbar uisearchcontroller

刚刚完成 Ray Wenderlich 的“UI 搜索 Controller ”教程,其中我创建了一个带有范围按钮项的搜索栏:

https://www.raywenderlich.com/113772/uisearchcontroller-tutorial

我让它工作没有问题,除了范围按钮与我的 TableView ScrollView 的第一个结果重叠的小异常(exception):Picture Here

在我的应用程序中,我使用的是嵌入 UIViewController 内的 tableView,我猜这可能是问题所在。我在 UIViewController 上检查了“调整 ScrollView 插入”,但没有解决问题。即使尝试取消选中它,也可能是问题所在,但仍然不起作用。

我认为问题与教程中将 searchBar 添加为 tableView 的 headerView 相关:

 tableView.tableHeaderView = searchController.searchBar

但是,我不知道为什么它不会对看起来像 UINavigationController 的东西造成任何问题,但对于将其嵌入到 UITableViewController 内的 tableView 上的人来说却会造成问题。

非常感谢任何帮助/解决方法建议!提前非常感谢您。

编辑:实例化搜索 Controller 的代码,如下 Wenderlich 教程:

        searchController.searchBar.scopeButtonTitles = ["All","party", "hangout", "recreation", "event", "other"]
        searchController.searchBar.tintColor = UIColor().crimson()

        searchController.searchBar.delegate = self

        //MARK: Search controller initialization
        searchController.searchResultsUpdater = self
        searchController.dimsBackgroundDuringPresentation = false

最佳答案

答案发现:在tableView中实现heightForHeaderInSection方法并返回高度。答案可以在这里找到:

https://stackoverflow.com/a/32996842/7389684

关于ios - UISearchController 重叠 TableView 的 ScrollView 。解决这个问题的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45596357/

相关文章:

ios - 在 Swift 的 MailJet 电子邮件中附加 PDF

string - 从 NSUserDefaults.standardUserDefaults().dictionaryRepresentation().keys 获取 [String]

ios - 尽管使用较弱的委托(delegate)保留圈

ios - 在自定义表格 View ios 中显示按钮

ios - 无法使用 editActionsForRow 推送 View Controller

iOS/Admob 7.20 - 无法使用测试 adUnitID 展示原生广告

ios - 我如何从 Apple 获得应用程序内购买的付款? (iOS iTunes 连接)

ios - 我想在 objective-c 中使用无填充的 CFB 加密创建 AES 128

ios - 点击附件按钮时更改 contentView

iphone - UITableViewDataSource 委托(delegate)