我試圖在表格滾動時將查找欄保留在視圖中。目前,我將它作爲桌面視圖中的標題放置,並且按其應有的方式工作,但當然,當您沿着桌子向下搜索欄時,搜索欄會滾動屏幕。我想我能做到這一點簡單地修改這個代碼示例:如何將UISearchController的searchBar設置爲不是tableHeaderView或navigationItem.titleview的視圖?
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。
我錯過了什麼嗎?
添加
UISearchController
該視圖的搜索欄,如果你有實現代碼如下上述空白的UIView的地方,比方說你有一個出口,以調用'searchContainer'空白的UIView ,那麼你可以通過'searchContainer.addSubview(searchController.searchBar)' –將搜索欄添加到該視圖。添加並回答,你會得到更多的積分。 – Carlos