在 UITabBarController 中使用 UINavigationController 时 UISearchBar 被切断 [英] UISearchBar gets cut off when using a UINavigationController inside a UITabBarController

查看:15
本文介绍了在 UITabBarController 中使用 UINavigationController 时 UISearchBar 被切断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 UITabBarController 中的一个选项卡中实现一个搜索栏,该选项卡是 UINavigationController 中的一个 UITableViewController...我正在学习 Apple 教程 - 我尝试了很多不同的选项,包括这里提到的答案

一旦我点击它:

解决方案

好的,问题终于解决了.这条线让它工作

self.extendedLayoutIncludesOpaqueBars = true

我的 TabBar 不是半透明的,所以我认为这不会有什么不同,但我在我的 UITableviewcontroller(显示 UISearchController 的控制器)上设置了它,现在搜索在导航栏中正确显示.我在顶部和下方也有延伸边缘底部栏设置为 true(使用 Interface Builder)

I am trying to implement a search bar within one of the tabs in my UITabBarController, the tab is a UITableViewController within a UINavigationController...I am following an Apple tutorial - I have tried a lot of different options including answers mention here

Search bar gets cut off when using UISearchController with a UITabBarController inside a UINavigationController

I have tried setting the following property using

self.definesPresentationContext = true

or

self.tabBarController?.definesPresentationContext = true

Here is my code (from UITableViewController containing 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
}

Here's an image of the searchbar:

And once I tap it:

解决方案

Ok, finally solved the issue. This line got it to work

self.extendedLayoutIncludesOpaqueBars = true 

My TabBar isn't translucent so I didn't think that would make a difference but I set that on my UITableviewcontroller (the controller that is displaying the UISearchController) and now search displays in the navbar correctly. I also had extend edges under top & bottom bars set to true (using Interface Builder)

这篇关于在 UITabBarController 中使用 UINavigationController 时 UISearchBar 被切断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆