UISearchController: show results even when search bar is empty

前端 未结 14 2257
独厮守ぢ
独厮守ぢ 2020-12-23 13:27

As I understand, the default behaviour of UISearchController is:

  1. On tapping search bar, background is dimmed and \'cancel\' button is shown.
14条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 13:44

    Swift 3 Version:

    If your searchResultController is not nil and you are using a separate table view controller to show the search results, then you can make that table view controller conform to UISearchResultUpdating and in the updateSearchResults function, you can simply unhide the view.

    func updateSearchResults(for searchController: UISearchController) {
        view.hidden = false
    }
    

    Swift 4 Version:

    func updateSearchResults(for searchController: UISearchController) {
        view.isHidden = false
    }
    

提交回复
热议问题