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. windows phone 页面导航(6)

    原文:windows phone 页面导航(6) 页面导航的例子我们使用的是两个页面,从第一个页面(MainPage)导航到第二个页面(SecondPage),然后可以从第二个页面导航到第一个页面 , ...

  2. webservice一片:其中在外线呼叫数据,查看返回数据

    经Android数据被访问,返回的数据(json格公式,object数据类型:strJson) 业务需求:经webservice调用外部暴露数据并返回json数据序列化.阅读到数据库表:[SQ_Eve ...

  3. Android定义自己的面板共享系统

    在Android分享知道有一个更方便的方法.调用的共享面板来分享我们的应用程序的系统.主要实现例如,下面的: public Intent getShareIntent(){ Intent intent ...

  4. hdu 4885 (n^2*log(n)推断三点共线建图)+最短路

    题意:车从起点出发,每次仅仅能行驶L长度,必需加油到满,每次仅仅能去加油站或目的地方向,路过加油站就必需进去加油,问最小要路过几次加油站. 開始时候直接建图,在范围内就有边1.跑最短了,再读题后发现, ...

  5. BZOJ 3172([Tjoi2013]单词-后缀数组第一题+RMQ)

    3172: [Tjoi2013]单词 Time Limit: 10 Sec   Memory Limit: 512 MB Submit: 268   Solved: 145 [ Submit][ St ...

  6. Cocos性能优化工具的开发介绍Visual Studio内存泄漏检测工具——Visual Leak Detector

    然后,Windows下有什么好的内存泄漏检測工具呢?微软提供Visual Studio开发工具本身没有什么太好的内存泄漏检測功能.我们能够使用第三方工具Visual Leak Detector(下面简 ...

  7. effective c++ 条款8 prevent exception from leaving destructor

    1 析构函数绝对不要吐出异常.如果一个析构函数可能调用产生异常的函数,析构函数应该不传播该异常或结束程序 2 如果客户需要对某个操作函数运行期间抛出的异常做出反应,那么class应该提供一个普通函数执 ...

  8. effective c++ prefer const,enum, inline to #defines

    学习心得 对于纯常量,最好以const对象或者enums替换#define #define FIRST 3 //not good enum { first=1, second=2 } ; int nu ...

  9. java 线程、线程池基本应用演示样例代码回想

    java 线程.线程池基本应用演示样例代码回想 package org.rui.thread; /** * 定义任务 * * @author lenovo * */ public class Lift ...

  10. 【C++探索之旅】第一部分第二课:C++编程的必要软件

    内容简介 1.第一部分第二课:C++编程的必要软件 2.第一部分第三课预告:第一个C++程序 C++编程的必要软件 经过上一课之后,大家是不是摩拳擦掌,准备大干一场了呢. 这一课我们来做一些C++开发 ...