gpt4 book ai didi

ios - 搜索栏未显示在导航栏 iOS 11 上

转载 作者:搜寻专家 更新时间:2023-10-30 21:58:04 24 4
gpt4 key购买 nike

我正在将 viewController 推送到我想要搜索栏的地方,但搜索栏根本没有显示。下面是代码。我错过了什么吗?

var searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search here..."
definesPresentationContext = true
searchController.searchBar.delegate = self
searchController.searchBar.sizeToFit()
if #available(iOS 11.0, *) {

self.navigationItem.searchController = searchController
} else {
// Fallback on earlier versions
navigationItem.titleView = searchController.searchBar
navigationItem.titleView?.layoutSubviews()
}

最佳答案

您需要将这一行添加到您的代码中:

navigationItem.hidesSearchBarWhenScrolling = false

这会在滚动时移除隐藏的 searchBar,并在推送 View Controller 时显示它。

关于ios - 搜索栏未显示在导航栏 iOS 11 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51177387/

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