当我的搜索控制器处于活动状态时,每当我选择表行时,我的应用程序似乎就会崩溃。
注意事项:
-
-
我目前有一个修复程序,但是,它要求在选择表行时关闭搜索控制器。这导致用户界面体验不佳。我不想解雇我的搜索控制器
以下是我的一些代码:
class ViewProfileViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDataSource, UISearchBarDelegate, UISearchResultsUpdating {
let searchController = UISearchController(searchResultsController: nil)
override func viewDidLoad() {
super.viewDidLoad()
searchController.searchResultsUpdater = self
searchController.hidesNavigationBarDuringPresentation = false
searchController.dimsBackgroundDuringPresentation = false
searchController.searchBar.sizeToFit()
searchController.searchBar.searchBarStyle = .minimal
searchController.searchBar.placeholder = "Search City"
searchController.searchBar.showsCancelButton = true
searchController.searchBar.delegate = self
searchController.searchBar.backgroundColor = UIColor.white
self.myTable.tableHeaderView = searchController.searchBar
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
if searchController.isActive {
navigationController?.popViewController(animated: true)
dismiss(animated: true, completion: nil)
} else {
}
let mViewController = MController()
let navController = UINavigationController(rootViewController: mViewController)
present(navController,animated: true, completion: nil)
}
}