UISearchController: show results even when search bar is empty

前端 未结 14 2177
独厮守ぢ
独厮守ぢ 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:55

    I think you are mistaken.

    SearchResultsController only appears when there are results. This is slightly different than your interpretation.

    The results are loaded manually based on the text in the search bar. So you can intercept it if the search bar is empty and return your own set of results.

    0 讨论(0)
  • 2020-12-23 13:55

    If you don't want to dim the results, set the dimsBackgroundDuringPresentation property to false.

    This will make sure that the underlying content is not dimmed during a search.

    You will also have to make sure you return results even when the searchText is empty otherwise an empty tableview will be displayed.

    0 讨论(0)
提交回复
热议问题