我正在使用一个包含搜索 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()
}
最佳答案
您无法访问 TableView ,因为 UISearchController
配置错误导致它上面有一个不可见的层。
以这种方式修改 searchController
:
let searchController = UISearchController(searchResultsController: nil)
searchController.obscuresBackgroundDuringPresentation = false
searchController.definesPresentationContext = true
关于ios - 搜索栏处于事件状态时,快速 TableView 被锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59523664/