nar*_*ero 5 uisearchbar ios swift uisearchcontroller
我正在尝试在我的UITabBarController中的一个选项卡中实现一个搜索栏,该选项卡是UINavigationController中的UITableViewController ...我正在关注Apple教程 - 我尝试了很多不同的选项,包括这里提到的答案
在UINavigationController中使用带有UITabBarController的UISearchController时,搜索栏会被切断
我尝试使用设置以下属性
self.definesPresentationContext = true
Run Code Online (Sandbox Code Playgroud)
要么
self.tabBarController?.definesPresentationContext = true
Run Code Online (Sandbox Code Playgroud)
这是我的代码(来自UITableViewController,包含UISearchBar):
/// Search controller to help us with filtering.
var searchController: UISearchController!
/// Secondary search results table view.
var resultsTableController: SearchResultsTableController!
override func viewDidLoad() {
super.viewDidLoad()
resultsTableController = SearchResultsTableController()
resultsTableController.tableView.delegate = self
searchController = UISearchController(searchResultsController: resultsTableController)
searchController.searchResultsUpdater = self
searchController.searchBar.sizeToFit()
self.tableView.tableHeaderView = searchController.searchBar
searchController.delegate = self
searchController.dimsBackgroundDuringPresentation = true
searchController.searchBar.delegate = self // so we can monitor text changes
self.definesPresentationContext = true
}
Run Code Online (Sandbox Code Playgroud)
这是搜索栏的图片:
好的,终于解决了问题。这条线让它发挥作用
self.extendedLayoutIncludesOpaqueBars = true
Run Code Online (Sandbox Code Playgroud)
我的 TabBar 不是半透明的,所以我认为这不会产生影响,但我在 UITableviewcontroller (显示 UISearchController 的控制器)上设置了它,现在搜索正确地显示在导航栏中。我还将顶部和底部栏下的延伸边缘设置为 true (使用 Interface Builder)