gpt4 book ai didi

ios - 如何将 UISearchController 搜索栏设置为不是 tableHeaderView 或 navigationItem.titleview 的 View ?

转载 作者:IT王子 更新时间:2023-10-29 05:20:57 28 4
gpt4 key购买 nike

我试图在表格滚动时保持搜索栏在 View 中。目前,我将它作为表头放置在 TableView 中,它可以正常工作,但是当您沿着表向下移动时,搜索栏当然会滚动到屏幕之外。我想我可以简单地修改这个代码示例来做到这一点:

How do I use UISearchController in iOS 8 where the UISearchBar is in my navigation bar and has scope buttons?

searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.delegate = self
searchController.searchBar.delegate = self
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
tableview.tableHeaderView = searchContoller.searchBar // How to put it elsewhere?
//Alternative that also works
navigationItem.titleView = searchController.searchBar

这个想法是采取一些其他的观点并做

otherview = searchController.searchBar

例如 UISearchBar 的导出,或空白的 UIView,或类似的东西。

但如果我这样做,它不会显示 searchBar。它似乎只能作为表格的标题 View 或作为 navigationItem.titleView。

我错过了什么吗?

最佳答案

如果你有一个空白的 UIView 放在 tableview 上面。

假设您有一个名为 searchContainer 的空白 UIView 导出。然后,您可以通过添加以下行将 UISearchController 的搜索栏添加到该 View

searchContainer.addSubview(searchController.searchBar)

关于ios - 如何将 UISearchController 搜索栏设置为不是 tableHeaderView 或 navigationItem.titleview 的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30756825/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com