该场景是用户在UISearchController
中搜索数据,并且在过滤数据后,用户将在expandable cell
中敲击数据(对于我使用FoldingCell
窗格的可扩展单元格) 。但是当用户点击可扩展单元格时,键盘仍然可见。当用户点击可扩展单元格时,如何自动隐藏键盘?我只是在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
}