我有一个 UIViewController
,我通过显示它来打开它。其中 avec 只有一个 UITableView
和 UISearchController
:
let searchController = UISearchController(searchResultsController: nil)
if #available(iOS 11.0, *) {
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
navigationItem.searchController = searchController
navigationItem.hidesSearchBarWhenScrolling = false
definesPresentationContext = true
}
效果很好。每次用户更新 UISearchBar
字段时,我都可以过滤 UITableView
。
我的 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
函数是这样的:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
dismiss(animated: true, completion: nil)
}
我第一次在过滤 UItableView
后选择一行(当 UISearchBar 聚焦时)我的 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
是已调用,但 dismiss(animated: true, completion: nil)
不起作用。它只是 resignFristResponder()
UISearchBar
。
然后如果再次选择一个单元格,现在 UISearchBar
不再聚焦 dismiss(animated: true, completion: nil)
工作。
所以我必须选择一个单元格两次才能看到我的 UIViewController
被关闭。
这有什么问题吗?
最佳答案
首先尝试在 searchController 上调用 dismiss
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
searchController.dismiss(animated: false)
dismiss(animated: true)
}
我刚刚对此进行了测试,无论搜索是否处于事件状态,它都有效。
关于ios - UISearchController UITableView didSelectRowAtIndexPath 在过滤后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53169628/