除非我点击搜索栏,否则 SearchController 不会显示未过滤的结果

SearchController does not show unfiltered results unless I tap in the searchbar

我使用 searchController 在搜索所有用户列表时获得良好的用户体验。 但是我希望用户在进入 searchController 时看到未过滤的用户列表。到目前为止,正如标题中所写,只有在我点击搜索栏内部后才会显示未过滤的结果。在此之前,tableview 是空的。如果我然后按下内置取消按钮,未过滤的数据将保留。 搜索功能工作得很好,但这个错误使它在用户体验方面毫无用处。

我读到 searchController 可能会在开始时覆盖 tableview,但首先我不知道这是不是真的,其次,我不知道如何避免它。

有人知道如何解决这个问题吗?

您可以通过设置 isActive 属性 强制 UISearchController 显示自身。 https://developer.apple.com/documentation/uikit/uisearchcontroller/1618659-isactive

When the user taps in the search field of a managed search bar, the search controller automatically displays the search results controller. Usually, you get the value of this property to determine whether the search results are displayed. However, you can set this property to true to force the search interface to appear, even if the user has not tapped in the search field.

The default value of this property is false.