【问题标题】:Whole app freezes, when opening UISearchController in NavigationBar在 NavigationBar 中打开 UISearchController 时,整个应用程序冻结
【发布时间】:2020-02-13 22:25:51
【问题描述】:

我正在制作一个包含加密货币列表的应用程序。应该能够在这 3 个过滤列表(BTC、ETH、USD)中进行搜索。我唯一的问题是搜索栏。

只要我按下“放大镜”图标,搜索栏就会出现,但整个应用程序会冻结。我无法按“取消”,在栏中键入,将其关闭并移动 UITableView。我不明白这种行为的原因。

var searchController : UISearchController!

@IBAction func searchingButton(_ sender: Any) {
    searchController = UISearchController(searchResultsController: nil)
    searchController.delegate = self
    searchController.searchBar.delegate = self
    searchController.searchBar.placeholder = "All currency pairs"
    searchController.hidesNavigationBarDuringPresentation = false
    searchController.searchResultsUpdater = self
    definesPresentationContext = true
    navigationItem.searchController = self.searchController
    navigationItem.hidesSearchBarWhenScrolling = false

    searchButton.isHidden = true

    present(searchController, animated: true, completion: nil)
}


extension ViewController:  UISearchControllerDelegate {
    func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
        navigationItem.searchController = nil
        navigationController?.view.setNeedsLayout()
        navigationController?.view.layoutIfNeeded()
        self.indexChange(self.segmentedControl!)
    }
}

请帮我解决这个问题。如果需要,将提供更多代码。

【问题讨论】:

    标签: ios swift uisearchcontroller


    【解决方案1】:

    嗯,这很奇怪,但是清理项目和重新启动系统很有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-05
      • 2016-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      相关资源
      最近更新 更多