如何修复表视图的搜索栏与状态栏重叠 [英] How to fix table view's search bar overlapping with status bar

查看:121
本文介绍了如何修复表视图的搜索栏与状态栏重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在导航控制器中有一个UITableViewController,带有一个搜索栏。这是我在viewDidLoad中添加搜索栏的方式:

I have a UITableViewController inside a navigation controller, with a search bar. This is how I add the search bar in viewDidLoad:

let resultsController = SearchTableViewController()
resultsController.people = people
searchController = UISearchController(searchResultsController: resultsController)
let searchBar = searchController.searchBar
searchBar.placeholder = "Search a person"
searchBar.sizeToFit()
tableView.tableHeaderView = searchBar
searchController.searchResultsUpdater = resultsController

结果如下:

我尝试在故事板中编辑表格视图以添加约束以使其从顶视图的边距更远,但我无法添加约束,可能是因为表视图位于UITableViewController中。

I tried editing the table view in the storyboard to add a constraint to make it further from the top view's margins, but I can't add contraints, probably because the table view is inside a UITableViewController.

推荐答案

我认为你需要这段代码。

I think you need this code.

在你的 viewDidLoad 方法添加此代码:

In your viewDidLoad method add this code:

self.tableView.contentInset = UIEdgeInsetsMake(20, 0, 0, 0)

您的tableview将是这样的:

And your tableview will be something like this:

编辑:

您可以使用以下代码强制滚动表格:

You can forcely scroll table with this code:

tableView.scrollToRowAtIndexPath( NSIndexPath(index: 0), atScrollPosition: UITableViewScrollPosition.Top, animated: false)

这篇关于如何修复表视图的搜索栏与状态栏重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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