gpt4 book ai didi

ios - 搜索栏处于事件状态时,快速 TableView 被锁定

转载 作者:行者123 更新时间:2023-11-28 20:48:55 24 4
gpt4 key购买 nike

我正在使用一个包含搜索 Controller 的大型导航栏。如果我不搜索,我可以毫无问题地滚动浏览我的表格 View ,但如果我正在搜索,它就会像锁定一样接缝。这是我的代码:

func updateSearchResults(for searchController: UISearchController) {

// First we will check if input is only containing numbers => search for PLZ otherwise we will check if a restaurant is called like this otherwise search if there is a suitable city
self.navigationItem.title = searchController.searchBar.text!

if !searchController.isActive{
//TODO get all restaurants for default city
self.navigationItem.title = "München"

}
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "partnerscell", for: indexPath) as! PartnersCellTableViewCell

return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
var bounds = UIScreen.main.bounds
var width = bounds.size.width
var height = bounds.size.height
return height/2.2
}

@IBOutlet weak var tv: UITableView!
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
if #available(iOS 11.0, *) {
self.navigationController?.navigationBar.prefersLargeTitles = true
}

self.navigationController?.navigationBar.isTranslucent = true

self.navigationItem.searchController = searchController
self.navigationController?.navigationBar.shadowImage = UIImage()
}

此外,如果我正在搜索,我的工具栏看起来会更暗。请查看随附的两个屏幕截图:Searchbar is not active, scrolling is possible

Searchbar is active, scrolling impossible

最佳答案

您无法访问 TableView ,因为 UISearchController 配置错误导致它上面有一个不可见的层。以这种方式修改 searchController:

let searchController = UISearchController(searchResultsController: nil)
searchController.obscuresBackgroundDuringPresentation = false
searchController.definesPresentationContext = true

关于ios - 搜索栏处于事件状态时,快速 TableView 被锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59523664/

24 4 0