UISearchController

https://developer.apple.com/documentation/uikit/uisearchcontroller
A view controller that manages the display of search results based on interactions with a search bar.

  • 视图控制器,用于根据与搜索栏的交互来管理搜索结果的显示。

Overview

You use a search controller in tandem with your existing view controllers. When you have a view controller with searchable content, incorporate the search bar of a UISearchControllerobject into your view controller’s interface. When the user interacts with that search bar, the search controller automatically displays a new view controller with the search results that you specify.

  • 您可以将搜索控制器与现有视图控制器配合使用。 如果您有一个具有可搜索内容的视图控制器A,请将“UISearchController”对象的搜索栏合并到视图控制器A的界面中。 当用户与该搜索栏进行交互时,搜索控制器会自动显示包含您指定的搜索结果的新视图控制器。

A search controller works with two custom view controllers that you provide. The first view controller displays your searchable content and the second displays your search results. The first view controller is part of your app’s main interface and you display it in whatever way is appropriate for your app. You pass the second view controller to the init(searchResultsController:) method when you initialize your search controller, and the search controller displays that view controller at appropriate times.

  • 搜索控制器使用您提供的两个自定义视图控制器。 第一个视图控制器显示您的可搜索内容,第二个显示您的搜索结果。 第一个视图控制器是应用程序主界面的一部分,您可以以适合您的应用程序的任何方式显示它。 初始化搜索控制器时,将第二个视图控制器传递给init(searchResultsController :)方法,搜索控制器会在适当的时间显示该视图控制器。

Each search controller provides a UISearchBar object that you must incorporate into the user interface of your initial view controller. Add this object to the view containing your searchable contents. When the user taps the search bar to enter a search term, the search controller automatically displays your search results view controller and notifies your app that the search process has begun.

  • 每个搜索控制器都提供一个UISearchBar对象,您必须将该对象合并到初始视图控制器的用户界面中。 将此对象添加到包含可搜索内容的视图中。 当用户点击搜索栏以输入搜索词时,搜索控制器会自动显示搜索结果视图控制器,并通知您的应用程序搜索过程已开始。

When the user interacts with the search bar, the search controller notifies the object in its searchResultsUpdater property. You provide the search results updater object, which must conform to the UISearchResultsUpdating protocol. You use the methods of that protocol to search your content and deliver the results to your search results view controller. Typically, the view controller with your searchable content also acts as the search results updater object, but you can use another object if you prefer.

  • 当用户与搜索栏交互时,搜索控制器会在其searchResultsUpdater属性中通知对象。 您提供搜索结果updater对象,该对象必须符合UISearchResultsUpdating协议。 您可以使用该协议的方法搜索内容并将结果发送到搜索结果视图控制器。 通常,具有可搜索内容的视图控制器也可用作搜索结果更新程序对象,但如果您愿意,则可以使用其他对象。

To customize the presentation or dismissal of the search results controller, assign an object to the search controller’s delegate property. Delegate objects must conform to the UISearchControllerDelegate protocol. You use the methods of that protocol to be notified when the search controller itself is activated and when the search results controller is presented or dismissed.

  • 要自定义搜索结果控制器的显示或解除,请将对象分配给搜索控制器的委托属性。 委托对象必须符合UISearchControllerDelegate协议。 您可以在激活搜索控制器本身以及显示或关闭搜索结果控制器时使用该协议的方法进行通知。

Note

Although a UISearchController object is a view controller, you should never present it directly from your interface. If you want to present the search results interface explicitly, wrap your search controller in a UISearchContainerViewController object and present that object instead.

  • 虽然UISearchController对象是一个视图控制器,但是不应该直接从界面中显示它。 如果要显式显示搜索结果界面,请将搜索控制器包装在UISearchContainerViewController对象中,然后显示该对象。

For iOS, see Displaying Searchable Content by Using a Search Controller to learn how to implement a search controller in your app.

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 从这段介绍,可以知道这几个重点:1、UISearchController 的 delegate 和 searchR...
    iChanne阅读 1,412评论 0赞 0
  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 8,163评论 0赞 10
  • 二零一八年 四月十六日 最近越来越喜欢记忆,当然是因为记忆能力也越来越强,哈哈。对于这种探索自己大脑的神器之旅真的...
    子小木又同学阅读 240评论 1赞 1
  • 这个星期是特别的一周,宝贝,因为我们跨越了2017,迎来了2018。是的,新的一年就这样来到了。 感谢主,在201...
    水墨明眸阅读 259评论 0赞 0
  • 今天果然很懒,什么都没有做,回来摊在沙发上,直到深夜。即将回家小住,不知道考研的动力在哪里是不行的。是因为爱情?是...
    小Mizanin阅读 177评论 0赞 0

友情链接更多精彩内容