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
问题是添加标签栏后。搜索栏在导航栏后面。
最佳答案
我创建了与您相同的层次结构。
- 查看层次结构
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
}
}
- 输出:
关于ios - 添加标签栏后搜索栏放在导航下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44355562/