gpt4 book ai didi

ios - 无法与添加为 HeaderView 的 SearchBar 交互

转载 作者:行者123 更新时间:2023-11-30 12:21:15 25 4
gpt4 key购买 nike

我已将 SearchController 的搜索栏添加到 tableview Controller 的 headerview 中,但是当我点击搜索栏键盘时不会弹出。感觉就像没有用户交互。以下是用于将搜索栏添加到 uitableview 的代码。

  self.resultSearchController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.userInteractionEnabled = true
dispatch_async(dispatch_get_main_queue(),{
self.tableView.tableHeaderView = controller.searchBar
controller.searchBar.bounds = (self.tableView.tableHeaderView?.bounds)!
controller.definesPresentationContext = true
self.definesPresentationContext = true

})
return controller
})()

最佳答案

尝试在 viewDidLoad 中添加这 5 行代码并尝试一下

let searchController = UISearchController(searchResultsController: nil)
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
self.tableView.tableHeaderView = searchController.searchBar

关于ios - 无法与添加为 HeaderView 的 SearchBar 交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44763572/

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