ios - UISearchController UITableView didSelectRowAtIndexPath 过滤后不起作用
问题描述
我有一个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
}
它运作良好。UITableView
每次用户更新UISearchBar
字段时,我都可以过滤。
我的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
被解雇。
那有什么问题?
解决方案
Just Makey sure you are creating your search controller like this.
let searchController: UISearchController = {
let search = UISearchController(searchResultsController: nil)
search.definesPresentationContext = true
search.dimsBackgroundDuringPresentation = false
return search
}()
Especially this line. That solved my problem in ios 12
dimsBackgroundDuringPresentation = false
Once didSelectRow method starts getting called, put this line of code to dismiss Search Controller.
searchController.dismiss(animated: true, completion: nil)
推荐阅读
- laravel - 如何使用主管按顺序执行 laravel 队列作业?
- mongodb - Error: Configuration is not defined: topic
- momentjs - 如何仅使用服务器日期时间并忽略客户端日期时间?
- reactjs - 如何使用 eslint 规则 react-hooks/exhaustive-deps 警告无点函数表达式中的违规行为
- python - 如何在python中的字典函数内打印数组形状
- ios - 表格视图单元格的案例。迅速
- python-3.x - 使用python从嵌套字典创建数据框
- ios - 如何在 Storyboard 中嵌套视图控制器
- java - 在 ComboBox 对象中检索数组对象
- docker - Docker swarm 健康检查失败杀死容器 - 退出 0