gpt4 book ai didi

swift - 为什么我的 UITableView 滚动偏移在返回其 View 时最终位于 UISearchController 后面?

转载 作者:行者123 更新时间:2023-11-30 10:34:12 24 4
gpt4 key购买 nike

Xcode 11.1、iOS 13.1

我很难弄清楚为什么 TableView 单元格最终出现在搜索栏后面。

我的设置:

override func viewDidLoad() {
// Setup Eureka's UITableViewStyle to `Plain` (like 'Contacts' app)
// https://github.com/xmartlabs/Eureka/issues/218
if tableView == nil {
tableView = UITableView(frame: view.bounds, style: UITableView.Style.plain)
tableView?.autoresizingMask = UIView.AutoresizingMask.flexibleWidth.union(.flexibleHeight)
tableView.cellLayoutMarginsFollowReadableWidth = false
}
// *now* call super.
super.viewDidLoad()

// Add search bar
searchController.searchResultsUpdater = self
searchController.obscuresBackgroundDuringPresentation = false
definesPresentationContext = true

// Place the search bar in the navigation bar.
self.navigationItem.searchController = self.searchController
self.navigationItem.hidesSearchBarWhenScrolling = false
}

enter image description here

最佳答案

tableView = UITableView(frame: view.bounds, style: UITableView.Style.plain)之后添加以下约束

tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 0).isActive = true
tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 0).isActive = true
tableView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: 0).isActive = true
tableView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: 0).isActive = true

关于swift - 为什么我的 UITableView 滚动偏移在返回其 View 时最终位于 UISearchController 后面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58427513/

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