繁体   English   中英

如何将UISearchController的searchBar设置为不是tableHeaderView或navigationItem.titleview的视图?

[英]How do I set the UISearchController's searchBar to a view that isn't the tableHeaderView or navigationItem.titleview?

当桌子滚动时,我试图将搜索栏保持在视图中。 目前我将它作为标题放在一个tableview中,它可以正常工作,当然,当你走下桌子时,搜索栏会滚动离开屏幕。 我以为我可以这样做只需修改此代码示例:

如何在iOS 8中使用UISearchController,其中UISearchBar位于导航栏中并具有范围按钮?

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。 它似乎只能用作表的标题视图或navigationItem.titleView。

我错过了什么吗?

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

让我们假设您有一个名为searchContainer空白UIView的searchContainer 然后,您可以通过添加以下行将UISearchController的搜索栏添加到该视图

searchContainer.addSubview(searchController.searchBar)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM