UISearchDisplayController和UISearchBar一起使用用来管理UISearchBar和搜索结果的展示。UISearchDisplayController提供了显示搜索结果的tableview来覆盖原控制器的视图;

使用UISearchDisplayController须要:

  • 提供搜索结果table的数据的来源-searchResultsDataSource
  • 搜索结果table的代理 SearchResultsDelegate
  • UISearchDisplayController控制器的代理delegate ,对应搜索事件的開始结束和显示隐藏界面;(这个代理知道搜索字符串的改变和搜索范围,所以结果table可以(自己主动)又一次导入)
  • searchBar的代理(关于UISearchBar代理上篇文章已经说明)

一般是在在uitableview中初始化UISearchDisplayController来展示一个列表。

searchController = [[UISearchDisplayController alloc]
initWithSearchBar:searchBar contentsController:self];
searchController.delegate = self;
searchController.searchResultsDataSource = self;
searchController.searchResultsDelegate = self;

在tabelview代理方法中须要推断是哪一个table(UITableViewController中有self.tableView  UISearchDisplayController中有.searchResultsTableView)

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    if (tableView == self.tableView) {
return ...;
}
// If necessary (if self is the data source for other table views),
// check whether tableView is searchController.searchResultsTableView.
return ...;
}

一个UIViewController和一个UISearchBar仅仅有一个UISearchDisplayController。

你可以在ios7 之后,在navigationbar中使用SearchDisplayController,通过配置UISearchDisplayController中得displaysSearchBarInNavigationBar和
navigationItem属性;

相关的属性和方法

@property(nonatomic, getter=isActive) BOOL active

展现(是否隐藏)状态。默认值是NO。直接设置没有动画,用setActive:animated: 设置会有动画

@property(nonatomic,
assign) id<UISearchDisplayDelegate>
delegate

代理

@property(nonatomic,
assign) BOOL displaysSearchBarInNavigationBar

指定navigationbar中包括一个searchBar

@property(nonatomic,
readonly) UINavigationItem *navigationItem

仅仅读属性 代表在navigation controller的navigationbar中的searchdisplaycontroller;

@property(nonatomic, readonly) UISearchBar *searchBar

UISearchDisplayController中的UISearchBar;

@property(nonatomic,
readonly) UIViewController *searchContentsController

这个属性管理着搜索出的内容

@property(nonatomic,
assign) id<UITableViewDataSource>
searchResultsDataSource

展示搜索结果的数据来源

@property(nonatomic,
assign) id<UITableViewDelegate>
searchResultsDelegate

搜索结果展示的table的代理

@property(nonatomic,
readonly) UITableView *searchResultsTableView

搜索结果展示的table

@property(nonatomic,
copy) NSString *searchResultsTitle

搜索结果视图的标题

-
(id)initWithSearchBar:(UISearchBar *)searchBar contentsController:(UIViewController *)viewController

初始化控制器
指定关联的search 和view controller

- (void)setActive:(BOOL)visible animated:(BOOL)animated

展现或者隐藏搜索视图

内容来自苹果文档

最新文章

  1. array
  2. python configparser模块
  3. Tesseract-OCR识别中文与训练字库实例
  4. C#命名空间的嵌套
  5. shell基础
  6. 什么才是程序员的核心竞争力?zz
  7. 更改OS序列号(slmgr)
  8. ios开发之再谈设计模式
  9. svn经常使用命令具体解释(非常全,非常有用)
  10. JVM中GC浅解:垃圾回收的了解
  11. 数据库DDL操作
  12. Angular2.js——数据显示
  13. Linux进程管理(第二版) --计划任务
  14. github page 配置hexo 博客 的常见错误
  15. 【20190405】JavaScript-正则式匹配与替换结果解析
  16. 【A tour of go】练习题
  17. CentOS 7 安装配置带用户认证的squid代理服务器
  18. 【周年庆】china-pub 14周年庆感恩回馈四波狂热来袭
  19. GitBash: 右键添加 Git Bash Here 菜单
  20. InteliJ Idea pom.xml不自动提示的解决

热门文章

  1. Hibernate操作Clob数据类型
  2. cocos2d-x3.0 相对布局(一)
  3. java.lang.OutOfMemoryError: Java heap space错误和方法(集、转)
  4. Recall(检出率)和 Precision(准确性)
  5. MSSQL只能访问特定的数据库
  6. Java OCR tesseract 图像智能字符识别技术
  7. poj 2935 Basic Wall Maze
  8. android登陆接口调试
  9. Uva 10131 Is Bigger Smarter? (LIS,打印路径)
  10. 并发编程实践三:Condition