斯威夫特:searchBar仍可以通过navigationItem.hidesSearchBarWhenScrolling = true看到

时间:2018-12-29 05:57:04

标签: swift visible searchbar swift4.2

在Swift中,我试图实现隐藏的searchBar,在滚动时可以看到它,

我正在使用

navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = true

我尝试过移动以上代码,但是无论searchBar文件中的哪个位置ViewController都可见。

是否有overriding此功能? 我引用searchBarsearchController的文件中唯一的其他代码如下:

if self.searchController.isActive && searchController.searchBar.text != "" {...

self.searchController.searchBar.placeholder = "Search \(title)"

func updateSearchResults(for searchController: UISearchController) {

if let searchText = searchController.searchBar.text, !searchText.isEmpty {
        filteredArr = defaultArr.filter {...

func configureSearchController () {

    //Setup the Search Controller
    searchController.searchResultsUpdater = self
    searchController.hidesNavigationBarDuringPresentation = true
    searchController.dimsBackgroundDuringPresentation = false
    searchController.searchBar.searchBarStyle = .minimal
    searchController.definesPresentationContext = true
    navigationItem.searchController = searchController
    navigationItem.hidesSearchBarWhenScrolling = true 
}

// I call reloadData a few times throughout as well
tableView.reloadData()

我不确定以上任何一项如何影响hideSearchBarWhenScrolling = true

enter image description here

我很困惑这是怎么回事,有人有什么建议吗?

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

tableView“后面”的标签引起了问题:

searchBar始终可见:

enter image description here

searchBar按预期隐藏:

enter image description here