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

展现或者隐藏搜索视图

内容来自苹果文档

iOS UISearchDisplayController学习笔记的更多相关文章

  1. iOS音频学习笔记二:iOS SDK中与音频有关的相关框架

      上层:       Media Player Framework: 包含MPMoviePlayerController.MPMoviePlayerViewController.MPMusicPla ...

  2. iOS音频学习笔记一:常见音频封装格式及编码格式

    (1) pcm格式    pcm是经过话筒录音后直接得到的未经压缩的数据流    数据大小=采样频率*采样位数*声道*秒数/8     采样频率一般是22k或者44k,位数一般是8位或者16位,声道一 ...

  3. iOS开发学习笔记:基础篇

    iOS开发需要一台Mac电脑.Xcode以及iOS SDK.因为苹果设备都具有自己封闭的环境,所以iOS程序的开发必须在Mac设备上完成(当然,黑苹果应该也是可以的,但就需要花很多的精力去折腾基础环境 ...

  4. iOS开发学习笔记

    1 常用的第三方工具 1.1 iPhone Simulator 测试程序需要模拟器iPhone Simulator 1.2 设计界面需要Interface Builder,Interface Buil ...

  5. iOS - CAEmitterLayer 学习笔记一

    其他参考博客: http://my.oschina.net/u/2340880/blog/485095 http://www.cnblogs.com/YouXianMing/p/3785876.htm ...

  6. ios开发学习笔记(这里一定有你想要的东西,全部免费)

    1,Search Bar 怎样去掉背景的颜色(storyboard里只能设置background颜色,可是发现clear Color无法使用). 其实在代码里还是可以设置的,那就是删除背景view [ ...

  7. iOS开发应用学习笔记

    一.iOS应用设计 1. 参考资料: 解读iPhone平台的一些优秀设计思路 iPhone App的特点及基本设计方法 Mobile UI design and Developer 2. 用户对iPh ...

  8. ios 框架学习笔记

    ios主要的系统层次: 一.Cocoa Touch 层:创建应用程序主要使用的框架. 1.关键技术: AirDrop:实现应用间通信. Text Kit:处理文本和排版. UIKit Dynamics ...

  9. ios 存储学习笔记

    一.主要路径: Library/Caches/此文件用于存储那些需要及可延迟或重创建的临时数据.且这些内容不会被IOS 系统备份,特别地,当设备磁盘空间不足且应用不在运行状态时,IOS 系统可能会移除 ...

随机推荐

  1. 足球和oracle系列(3):oracle过程排名,世界杯第二回合战罢到来!

    足球与oracle系列(3):oracle进程排名.世界杯次回合即将战罢! 声明:        这不是技术文档,既然学来几招oracle简单招式.就忍不了在人前卖弄几下.纯为茶余饭后与数朋库友的插科 ...

  2. wxWidgets刚開始学习的人导引(1)——前言

    wxWidgets刚開始学习的人导引全文件夹   PDF版及附件下载 1 前言2 下载.安装wxWidgets3 wxWidgets应用程序初体验4 wxWidgets学习资料及利用方法指导5 用wx ...

  3. CodeForces 52C Circular RMQ(间隔周期段树,间隔更新,间隔总和)

    转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://codeforces.com/problemset/problem/52/C You are g ...

  4. 深入理解计算机系统之旅(四)处理器(CPU)的体系结构

    1.前言 处理器是很复杂的系统,它不是一蹴而就的,它是经过不断的升级.更新.设计之后的产物,而且如今还在保持着不断的更新. 处理器仅仅能运行一系列的指令,每条指令都仅仅是运行某个简单的操作,比方数字相 ...

  5. ASP.Net 重写IHttpModule 来拦截 HttpApplication 实现HTML资源压缩和空白过滤

    务实直接上代码: 1. 重写FilterModule.cs using System; using System.Collections.Generic; using System.Linq; usi ...

  6. CSAPP 六个重要的实验 lab5

    CSAPP  && lab5 实验指导书: http://download.csdn.net/detail/u011368821/7951657 实验材料: http://downlo ...

  7. sql function递归

    alter function Fn_GetUserGroupRelation ( @DHsItemID int ) returns nvarchar(1024) begin declare @Col_ ...

  8. Apache HTTP Server 与 Tomcat 的三种连接方式介绍(转)

    首先我们先介绍一下为什么要让 Apache 与 Tomcat 之间进行连接.事实上 Tomcat 本身已经提供了 HTTP 服务,该服务默认的端口是 8080,装好 tomcat 后通过 8080 端 ...

  9. Android 浏览器开发WebView setBlockNetworkImage本末

    含义本身防止网络数据图片 webSettings.setBlockNetworkImage(true); 停止发布数据 webSettings.setBlockNetworkImage(false); ...

  10. 【C语言探索之旅】 第二部分第五课:预处理

    内容简介 1.课程大纲 2.第二部分第五课: 预处理 3.第二部分第六课预告:   创建你自己的变量类型 课程大纲 我们的课程分为四大部分,每一个部分结束后都会有练习题,并会公布答案.还会带大家用C语 ...