从这段介绍,可以知道这几个重点: 1、UISearchController 的 delegate 和 searchResultsUpdater 可以设置为其他控制器; 2、UISearchController 弹出的搜索结果控制器和显示被搜索内容控制器之间是模态的关系,且 modalPresentationStyle 属性是 UIModalPresentationCurrentContext; 3、UISearchController 不应该被直接展示;

A UISearchController object manages the display of search results based on interactions with a search bar. 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 UISearchController  object 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. 一个UISearchController对象管理用户操作 search bar 后的搜索结果。搜索控制器层叠在已有的视图控制器上面。当你有一个可搜索内容的视图控制器时,将UISearchController 对象的 search bar 组合到这个视图控制器的界面上。在用户操作 search bar 时,搜索控制器自动显示一个新的视图控制器,它包含了你指定的搜索内容。

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 initWithSearchResultsController:  method when you initialize your search controller, and the search controller displays that view controller at appropriate times. 一个搜索控制器和你提供的两个自定义视图控制器一起工作。第一个视图控制器显示可搜索内容,第二个显示搜索结果。第一个视图控制器是 App 主界面的一部分,它在 App 中可能以任何合适的方式显示。在初始化搜索控制器时,将第二个视图控制器传给initWithSearchResultsController:方法,这样搜索控制器就能在合适的时间显示这个视图控制器。

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. For example, if you use a table view for your searchable contents, you can assign the search bar to the tableHeaderView  property of that table view. 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对象,必须将它加到初始视图控制器的界面上。 把它添加到包含可搜索内容的视图上。例如,如果你的可搜索内容是一个表视图,你可以把 search bar 赋值给表视图的tableHeaderView属性。当用户点击 search bar 并输入搜索条目时,搜索控制器自动显示你的搜索结果视图控制器,同时通知你的 App 搜索已经开始了。

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. 当用户操作 search bar 时,搜索控制器通知它自己的属性searchResultsUpdater的对象。你要提供更新搜索结果的对象,它必须遵循UISearchResultsUpdating协议。你可以使用协议中的方法搜索你的内容并将结果传递给搜索结果视图控制器。通常,由可搜索内容的视图控制器担任更新搜索结果的对象,但是你也可以使用其他对象。

Listing 1 shows how to configure a search controller from the view controller displaying the searchable content. This code creates another custom view controller for displaying the search results and uses that object to create the search controller object. The current view controller stores a reference to the search controller and handles updates when the search term changes. The view controller also acts as the presentation context for the search results, which is usually what you want. 代码1 显示了如何在可搜索内容的视图控制器上配置一个搜索控制器。下面的代码创建了一个自定义视图控制器用来显示搜索结果并用它来创建一个搜索控制器对象。当前视图控制器保存了搜索控制器的引用且在搜索条目改变时更新界面。这个视图控制器也可以作为搜索结果的展示上下文。

Listing 1Creating and configuring a search controller

// Create the search results controller and store a reference to it.

MySearchResultsController* resultsController = [[MySearchResultsController alloc] init];

self.searchController = [[UISearchController alloc] initWithSearchResultsController:resultsController];

// Use the current view controller to update the search results.

self.searchController.searchResultsUpdater = self;

// Install the search bar as the table header.

self.tableView.tableHeaderView = self.searchController.searchBar;

// It is usually good to set the presentation context.

self.definesPresentationContext = YES;复制代码

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. 为了能够自定义展示或者dismiss 搜索结果控制器,给搜索控制器的delegate属性分配一个对象。委托对象必须遵循UISearchControllerDelegate协议。搜索控制器在激活时、展示后、dismiss 后会通知协议中的方法。

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对象中,然后展示这个对象。

苹果文档 UISearchController的介绍相关推荐

  1. 源代码文档生成 Doxygen介绍(转载)

    源代码文档生成 Doxygen介绍(转载) 收藏 Doxygen介绍 一.Doxygen介绍 在项目开发过程中最重要的是如何和团队中其它成员沟通,如何在项目完成后减低维护成本,随着公司的人员流动,怎样 ...

  2. 文档中没有介绍的SQL Server DBCC命令

    文档中没有介绍的SQL Server DBCC命令 http://www.searchdatabase.com.cn/showcontent_11822.htm http://www.searchda ...

  3. 文档理解最新技术介绍 | DAS 2020 Keynote Speech

    DAS 2020 (Document Analysis System,文档分析系统研讨会) 于 7月26-29日在武汉召开,本次研讨会中有不少精彩的内容,昨天向大家推荐了来自华南理工大学金连文老师和 ...

  4. 掘金量化—Python SDK文档—5.API 介绍(2)

    Python SDK文档 5.API介绍 5.6通用数据函数(免费) python 通用数据 API 包含在 gm3.0.148 版本及以上版本,不需要引入新库 get_symbol_infos - ...

  5. Sandcastle帮助文档生成器使用介绍

    一.软件介绍 Sandcastle是一个管理类库的文档编译器,是用于编译发布组件(Assembly)信息的一个工具,这个工具通过反射和 Xslt技术,可以从dll文件及其xml注释(命令行编译时加/d ...

  6. 一款适合IT团队的在线API文档、技术文档工具-showdoc介绍

    还在为word文档传来传去查阅不方便而烦恼吗,还在为查看数据库字段含义不方便而烦恼吗,还在为编写接口文档而烦恼吗?今天为大家推荐一款适合IT团队的在线API文档.技术文档工具,有免费开源和在线托管的版 ...

  7. Word2016文档“比较”功能介绍及其Bug处理(Bug能让人睡不着觉)

    word比较功能使用步骤 Word2016文档"比较"功能 步骤 1:打开word比较功能 步骤 2:选择原文档和待比较文档 步骤 3:选择要比较的内容 步骤 4:得到比较结果 步 ...

  8. BRD、MRD、PRD文档撰写工具介绍-----产品经理深入浅出课程

    本文是针对多贝网 刘文智老师 产品经理深入浅出课程 课时9的总结.        课时9简要介绍了产品经理专业技能之BRD.MRD.PRD文档的撰写.        本文主要介绍撰写三大文档的主要工具 ...

  9. 1.8 centos7 的PATH、cp/mv/文档查看命令介绍

    环境变量PATH 什么是环境变量?环境变量一般是指在操作系统中用来指定操作系统运行环境的一些参数,如:临时文件夹位置和系统文件夹位置等. [root@centos7 ~]# echo $PATH #查 ...

最新文章

  1. 细数技术指标-[转载]
  2. centos7安装ftp_python 编译安装
  3. C++ Primer 5th笔记(chap 18 大型程序工具)命名空间
  4. boost::gil模块沿 x 轴计算梯度的方法的示例
  5. 表的插入、更新、删除、合并操作_14_ 通过表关联更新多个表多个字段
  6. iview代码片段 去除水平menu底部横线
  7. VC++ 6.0 与VS2008 C++ DEBUG工具(Windows)介绍
  8. 怎样彻底删除系统服务项
  9. Linux系统基本操作(一)—光盘挂载/卸载
  10. RPM方式安装MySQL5.5.48 (Aliyun CentOS 7.0 卸载MySQL5.7)
  11. [译]应用内搜索功能实现 Android TV应用程序手册教程十三
  12. MyBatis的常见面试题
  13. python的序列之列表
  14. VS2008快捷键总结
  15. xshell 与 xftp 免费版使用
  16. 基于FFmpeg的编解码器设计实现方案
  17. 求轮廓最大内接圆(后续篇)---距离变换法
  18. 兜兜转转还是回到程序员圈子
  19. Mermaid制作甘特图
  20. 微信小程序的脚本就是c语言,新手尝试编写微信小程序(2)——我的第一个微信小程序...

热门文章

  1. 初始Java DVD项目
  2. Listview的点击效果
  3. 【Linux 驱动】第九章 与硬件通信
  4. showModalDialog和showModelessDialog使用心得
  5. linux统计文件的个数
  6. pandas groupby
  7. 【Java常识】7.0 数组实现冒泡排序、选择排序和二分查找
  8. 为什么重新new两个线程线程号相同_面试官每次问我关于线程间通信方法,我都回答的很糟糕...
  9. gitlab提交合并_notification - 如何把gitlab项目中的提交、PUSH、合并请求的通知发送到邮箱...
  10. C语言如何实现泛型编程?