簡體   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