gpt4 book ai didi

ios - 搜索栏与节标题 View 重叠

转载 作者:可可西里 更新时间:2023-11-01 03:32:48 24 4
gpt4 key购买 nike

我将 searchBar 放在 tableHeaderView 中。在 iphone 6 上一切正常,但在 iphone 5s 上我得到了这个奇怪的结果?

 override func viewDidLoad() {
super.viewDidLoad()
tableView.delegate = self
tableView.dataSource = self
tableView.sectionIndexColor = Constants.Colors.ThemeGreen
tableView.sectionIndexBackgroundColor = UIColor.clearColor()
tableView.sectionIndexTrackingBackgroundColor = UIColor.clearColor()
tableView.contentInset = UIEdgeInsetsMake(0, 0, CGFloat(Constants.Dimensions.TabBarHeight), 0)
resultSearchController = UISearchController(searchResultsController: nil)
resultSearchController.searchResultsUpdater = self
resultSearchController.dimsBackgroundDuringPresentation = false
resultSearchController.definesPresentationContext = true
tableView.tableHeaderView = resultSearchController.searchBar
resultSearchController.searchBar.sizeToFit()

//Fetch data for the first time
do{
try fetchedResultsController.performFetch()
listHeaderView?.count = "\(fetchedResultsController.fetchedObjects!.count)"
}catch{
print("Error - Couldn't fetch list")
}
  • 注意:我正在使用 NSFetchedResultController 来检索数据

enter image description here

最佳答案

这是解决方案。不要在将 searchBar 放入 tableHeaderView 之后调用 sizeToFit(),而是在之前调用它。幕后到底发生了什么……我想知道……

resultSearchController.searchBar.sizeToFit() //Important to call sizeToFit BEFORE adding it to tableHeaderView or you get layout issues
tableView.tableHeaderView = resultSearchController.searchBar

关于ios - 搜索栏与节标题 View 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35284605/

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