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

标签 ios swift uitableview uisearchcontroller

我正在使用一个包含搜索 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/

相关文章:

ios - 将 UIView 移动到 UITableView 之上 - 触摸顶部 UIView 仍会选择表格行

objective-c - 将 map 居中到可见区域

ios - Cocoapods 库在单元测试期间未正确返回 isKindOfClass

ios - 您如何以 YYYY-MM-DD 格式快速获取上周日期?

ios - 遇到这个警告该如何解决?

swift - 如何在 Swift 中使用返回 MultiArray(Double) 的模型进行预测

ios - Xcode 8.0 中的词法或预处理器问题

ios - 有谁知道如何获取选择器 View 的值(value)并将该值发送到 View Controller 的另一个选择器 View

ios - 从 url 下载数据时等待填充表格 View

ios - 在单个 tableview 单元格中显示两个数组值