Сценарий состоит в том, что пользователь ищет данные в UISearchController
, и после того, как он отфильтрует данные, пользователь будет нажимать данные в expandable cell
(Для расширяемой ячейки я использовал FoldingCell
pod). Но когда пользователь касается расширяемой ячейки, клавиатура все еще видна. Как я могу автоматически скрыть клавиатуру, когда пользователь касается расширяемой ячейки? Я просто ищу возможные методы здесь, в SO, но это не работает для моего приложения. Любая ссылка или решение, которое вы можете порекомендовать, чтобы я мог использовать?
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath) as! FoldingCell
if cell.isAnimating() {
return
}
var duration = 0.0
if cellHeights[(indexPath as NSIndexPath).row] == kCloseCellHeight { // open cell
cellHeights[(indexPath as NSIndexPath).row] = kOpenCellHeight
cell.unfold(true, animated: true, completion: nil)
duration = 0.3
} else {// close cell
cellHeights[(indexPath as NSIndexPath).row] = kCloseCellHeight
cell.unfold(false, animated: true, completion: nil)
duration = 0.5
}
UIView.animate(withDuration: duration, delay: 0, options: .curveEaseOut, animations: { () -> Void in
tableView.beginUpdates()
tableView.endUpdates()
}, completion: nil)
self.view.endEditing(true)
}
ConfigureSearchBar
func configureSearchBar() {
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
searchController.searchBar.resignFirstResponder()
searchController.searchBar.textColor = UIColor.black
searchController.searchBar.placeholder = "Search by name, department or employee number"
searchController.searchBar.searchBarStyle = .prominent
searchController.searchBar.barTintColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255, alpha: 1.0)
searchController.searchBar.tintColor = UIColor.black
searchController.searchBar.backgroundColor = UIColor(red: 255/255.0, green: 255/255.0, blue: 255/255, alpha: 1.0)
searchController.searchBar.setImage(#imageLiteral(resourceName: "search-2"), for: .search, state: .highlighted)
searchController.searchBar.setShowsCancelButton(false, animated: true)
searchController.searchBar.isTranslucent = true
self.ParticipantTableView.tableHeaderView = searchController.searchBar
}