How to exit from the search on clicking on Cancel button?

前端 未结 10 1168
谎友^
谎友^ 2021-02-07 01:22

I have a search bar with cancel button. But when I click on Cancel button it doesn\'t close the search bar. How can I make that on click on Cancel it will return search bar to t

10条回答
  •  再見小時候
    2021-02-07 01:24

    I am also come across with this problem, in my case after searching any item from table view than click one of the result item it's opened details view but search bar does not disappeared. I use Nicat's answer with a little changes, here is my version:

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    
        searchController.isActive = false
        self.searchBarCancelButtonClicked(searchController.searchBar)
    
        ...
    }
    

提交回复
热议问题