我为tableView构建了一个UISearchBar,它可以过滤用户名...到目前为止非常好,但是现在我想在tableView的单元格被过滤时执行搜索,但是只要我单击一个单元格,回到originViewController
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
dismiss(animated: true) {
print("Dismiss completed")
let user = self.users[indexPath.row]
self.messagesController?.showChatControllerForUser(user)
}
searchController.isActive = false
}
searchBar函数
func searchBarIsEmpty() -> Bool {
// Returns true if the text is empty or nil
return searchController.searchBar.text?.isEmpty ?? true
}
func isFiltering() -> Bool {
return searchController.isActive && !searchBarIsEmpty()
}
func filterContentForSearchText(_ searchText: String, scope: String = "All") {
filtered = users.filter({( user : User) -> Bool in
return (user.name?.lowercased().contains(searchText.lowercased()))!
})
tableView.reloadData()
}
编辑:
func showChatControllerForUser(_ user: User) {
let chatLogController = ChatLogController(collectionViewLayout: UICollectionViewFlowLayout())
chatLogController.user = user
navigationController?.pushViewController(chatLogController, animated: true)
}