2017-06-04 114 views
1

在tableView中有一个搜索栏。
而且我也有一个导航控制器
搜索栏位于导航栏下方。
添加标签栏后在导航下搜索栏位

导航视图控制器是入口点。
关系根视图控制器到标签栏控制器

和搜索栏在postViewController.Swift创建
关系标签栏视图控制器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 

问题是在添加一个标签栏之后。搜索栏位于导航栏后面。

+0

你在哪里添加的标签栏? – PGDev

+0

@PGDev我添加了有问题的信息。 –

回答

0

我创建了和你一样的层次结构。

  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 
    } 
} 
  • 输出:
  • enter image description here

    +0

    谢谢。照片无法加载。但我们的代码是一样的,但我的搜索栏有问题。 –

    +0

    你在说什么照片?搜索栏面临的问题是什么? – PGDev