ios - 添加标签栏后搜索栏放在导航下方

标签 ios swift uisearchbar

tableView 中有一个搜索栏。
我也有一个导航 Controller
搜索栏位于导航栏下方。

导航 View Controller 是入口点。
关系 Root View Controller 到标签栏 Controller

搜索栏是在 postViewController.Swift 中创建的
标签栏 View Controller 与 postViewController 的关系

设置:

 searchController.searchResultsUpdater = self
        searchController.hidesNavigationBarDuringPresentation = false
        searchController.dimsBackgroundDuringPresentation = false
        searchController.searchBar.sizeToFit()
        searchController.searchBar.placeholder = "Search for the user id here ... "
        self.tableView.tableHeaderView = searchController.searchBar
        //blew code hides search bar on next page
        self.definesPresentationContext = true

问题是添加标签栏后。搜索栏在导航栏后面。

最佳答案

我创建了与您相同的层次结构。

  1. 查看层次结构

enter image description here

2.PostViewController

class PostViewController: UIViewController
{
    @IBOutlet weak var tableView: UITableView!
    @IBOutlet var searchBar: UISearchBar!

    override func viewDidLoad()
    {
        super.viewDidLoad()
        self.tableView.tableHeaderView = self.searchBar
        //You can customize the controller and searchBar according to your requirement.
    }
}

extension PostViewController: UITableViewDataSource, UITableViewDelegate
{
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return 3
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
    {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.text = "Hello"
        return cell
    }
}
  1. 输出:

enter image description here

关于ios - 添加标签栏后搜索栏放在导航下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44355562/

相关文章:

ios - 在 Swift 4 中从 uitextfields 将数据发布到服务器

ios - UIAppearance 移除 MFMailComposeViewController 的自定义 NavBar 背景

ios - iOS 应用程序需要 OnDemand VPN,随机断开连接

swift - 在 collectionview 单元格中添加到 uiview 时点击手势无法按预期工作

ios - 使用未声明的标识符 searchBar

ios - UISearchBardelegate 函数没有响应

ios - 获取parentViewController实例

ios - Collection View 单元格在 swift 中缓慢检测所选项目

ios - 将参数传递给 Swift 中的选择器函数

uisearchbar - 在位于 navigationItem titleView 的 ui 搜索栏右侧添加按钮