gpt4 book ai didi

ios - 搜索栏处于事件状态时无法选择 TableViewCell - iOS Swift

转载 作者:可可西里 更新时间:2023-11-01 04:55:50 26 4
gpt4 key购买 nike

我有一个连接到表格 View 的搜索栏。当搜索栏未处于事件状态时,它的工作原理与我想要的完全一样,但当搜索栏处于事件状态时,单元格选择被禁用。我已经对其进行了调试,当我在搜索处于事件状态时选择一行时,甚至没有调用 didSelectRowAtIndexPath。可能是什么原因造成的?

相关代码如下:

class FabricsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate, UISearchControllerDelegate, UISearchDisplayDelegate {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

searchController.delegate = self
searchController.searchBar.delegate = self
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
searchController.definesPresentationContext = false
searchController.hidesNavigationBarDuringPresentation = false
myTableView.tableHeaderView = searchController.searchBar

}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if searching {
searching = false
searchBar?.resignFirstResponder()
FirebaseClient.sharedInstance.joinFabric(uid: self.appDelegate.uid!, fabricKey: allFabrics[indexPath.row].key)
updateFabricList()
} else {
appDelegate.selectedFabricKey = joinedFabrics[indexPath.row].key
performSegue(withIdentifier: "fabricSelected", sender: self)
}
myTableView.deselectRow(at: indexPath, animated: false)
}

func filterContentForSearchText(searchText: String, scope: String = "All") {
if let allFabrics = allFabrics {
filteredFabrics = allFabrics.filter { fabric in
return (fabric.name.lowercased().contains(searchText.lowercased()))
}
myTableView.reloadData()
myTableView.setContentOffset(CGPoint.zero, animated: false)
}
}

}

extension FabricsViewController: UISearchResultsUpdating {
func updateSearchResults(for: UISearchController) {
filterContentForSearchText(searchText: searchController.searchBar.text!)
}
}

最佳答案

  1. 请检查您的方法名称的文本。确保您使用的方法名称如下:

覆盖 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

  1. 您已将 searchBar 的委托(delegate)设置为 self。当搜索激活时,您是否激活任何点击手势?此点击手势可能会中断您的 didSelectRowAtIndexPath 方法。

关于ios - 搜索栏处于事件状态时无法选择 TableViewCell - iOS Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41307138/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com