gpt4 book ai didi

ios - 如何修复表格 View 的搜索栏与状态栏重叠

转载 作者:搜寻专家 更新时间:2023-10-30 22:35:35 25 4
gpt4 key购买 nike

我在导航 Controller 中有一个 UITableViewController,带有一个搜索栏。这就是我在 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

这是结果:

enter image description here

我尝试在 Storyboard 中编辑 TableView 以添加约束以使其远离顶 View 的边距,但我无法添加约束,可能是因为 TableView 位于 UITableViewController 内。

最佳答案

我想你需要这段代码。

在您的 viewDidLoad 方法中添加此代码:

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

你的 tableview 将是这样的:

enter image description here

编辑:

你可以用这段代码强制滚动表格:

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

关于ios - 如何修复表格 View 的搜索栏与状态栏重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30818231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com