【发布时间】:2019-04-09 17:05:11
【问题描述】:
我有一个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 被解雇。
这有什么问题?
【问题讨论】:
-
我终于找到了答案here
-
我提出了一个副本,它将您的问题链接到您找到答案的位置
标签: ios uitableview uisearchbar uisearchcontroller dismiss