我正在使用 tableview
数据实现 SearchController
。在这里,Once searched particular data after that clicking search result cell to moving another detail page.现在,如果我回到主视图 Controller 搜索 Controller 显示而不解雇。我尝试了下面的代码,它在主视图 Controller 场景的细节方面工作正常,但如果我单击没有搜索文本的单元格,那么它会崩溃。如何解决?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let section = isFiltering ? filteredSections[indexPath.section] : sections[indexPath.section] // without search text I am getting index out of range issue
let item = section.result[indexPath.row]
let detailsVC = self.storyboard?.instantiateViewController(withIdentifier: "detailviewcontroller") as! DetailViewController
let navigationController = UINavigationController(rootViewController: detailsVC)
self.present(navigationController, animated: true, completion: nil)
// Search Dismiss - without search text if click tableview cell I am getting crash
// MARK: Validate SearchController isActive or Not.
if searchController != nil {
// Get rid of searchController
searchController.searchBar.endEditing(true)
searchController.isActive = false
searchController.dismiss(animated: true) { /* */ }
}
}
最佳答案
这可能是因为您的 searchController 尚未启动。只需首先检查 searchController != nil
。
关于ios - 如何在使用 Swift 单击 UITableview 单元格之前检查 SearchController 是否处于事件状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57802372/