我正在制作一个带有加密货币列表的应用。应该可以在这三个过滤列表(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!)
}
}
请帮助我解决这个问题。如果需要,将提供更多代码。
嗯,很奇怪,但是清理项目和重新启动系统很有帮助。